<?php
include_once(APP_PATH."/collect/config.php");
include_once(APP_PATH . "/myzhuaqu.php");
include_once(APP_PATH . "/collect/Lib/ORG/Zqnews.class.php");
include_once(APP_PATH . "/collect/Common/common.php");
include_once(APP_PATH . "/collect/reset/nodecode_inc.php");
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverExpectedCondition;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\WebDriverJavascriptExecutor;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverWait;
use Facebook\WebDriver\Interactions\WebDriverActions;
use Facebook\WebDriver\Cookie;
use Facebook\WebDriver\Remote\RemoteWebElement;
use Facebook\WebDriver\ExpectedConditions;

if (!function_exists("createdir")) {
    function createdir($filepath)
    {
        $nn = preg_split("/(?<!\:)\//", $filepath);
        $temppath = "";
        for ($i = 0; $i < count($nn); $i++) {
            $temppath .= (($i > 0) ? "/" : "") . $nn[$i];
            if (!is_dir($temppath)) {
                @mkdir($temppath, 0777);
            }
        }
    }
}


if (!function_exists("u")) {
    function u($text)
    {
        $new = array();
        if (is_array($text)) {
            foreach ($text as $k => $v) {
                $new[u($k)] = u($v);
            }
            $text = $new;
        }
        if (is_object($text)) {
            $text = array2object(u(object2array($text)));
        }
        if (is_string($text)) {
            $text = iconv("GB2312", "utf-8//IGNORE", $text);
        }
        return $text;
    }
}

if (!function_exists("g")) {
    function g($text)
    {
        if (is_array($text)) {
            $new = array();
            foreach ($text as $k => $v) {
                $new[g($k)] = g($v);
            }
            $text = $new;
        }
        if (is_object($text)) {
            $text = array2object(g(object2array($text)));
        }
        if (is_string($text)) {
            $text = iconv("UTF-8", "GB2312//IGNORE", $text);
        }
        return $text;
    }
}

function object2array(&$object)
{
    //$object = json_decode(json_encode($object), true);
    $arr=array();
    if(!empty($object)) {
        foreach ($object as $k => $v) {
            if (is_string($v)) {
                if (preg_match("/^[0-9]+$/", trim($k))) {
                    $arr[] = $v;
                } else {
                    $arr[$k] = $v;
                }
            } else {
                $arr[] = object2array($v);
            }
        }
    }
    return $arr;
}

function array2object($arrGiven)
{
    $objResult = new stdClass();
    foreach ($arrGiven as $key => $value) {
        if (is_array($value)) $value = array2object($value);
        $objResult->{$key} = $value;
    }
    return $objResult;
}


function isutf8($string)
{
    $str_len = strlen($string);
    for ($i = 0; $i < $str_len;) {
        $str = ord($string[$i]);
        if ($str >= 0 && $str < 0x7f) {
            $i++;
            continue;
        }
        if ($str < 0xc0 || $str > 0xfd) return false;
        $count = ($str > 0xFC ? 5 : $str > 0xf8) ? 4 : ($str > 0xf0 ? 3 : ($str > 0xe0 ? 2 : 1));
        if ($i + $count > $str_len) return false;
        $i++;
        for ($m = 0; $m < $count; $m++) {
            if (ord($string[$i]) < 0x80 || ord($string[$i]) > 0xbf) return false;
            $i++;
        }
    }
    return true;
}


function getIP()
{
    if (!empty ($_SERVER ["HTTP_CLIENT_IP"])) {
        $cip = $_SERVER ["HTTP_CLIENT_IP"];
    } else if (!empty ($_SERVER ["HTTP_X_FORWARDED_FOR"])) {
        $cip = $_SERVER ["HTTP_X_FORWARDED_FOR"];
    } else if (!empty ($_SERVER ["REMOTE_ADDR"])) {
        $cip = $_SERVER ["REMOTE_ADDR"];
    } else {
        $cip = '';
    }
    preg_match("/[\d\.]{7,15}/", $cip, $cips);
    $cip = isset ($cips [0]) ? $cips [0] : 'unknown';
    unset ($cips);
    return $cip;
}

if (!function_exists("strip_jscss")) {
    function strip_jscss($str, $lie_a = false)
    {
        preg_match_all("/<script\b[^<>]*>.*<\/\s*script\s*\/?>/Uisx", $str, $nn);
        if(!empty($nn[1])) {
            for ($i = 0; $i < count($nn[1]); $i++) {
                if (preg_match("/reload|AC_FL_RunContent/Uisx", $nn[0][$i])) {
                    if (preg_match("/http\:\/\/([^<>]*.swf)/Uisx", $nn[0][$i], $mm)) {
                        $str = str_replace($nn[0][$i], "[media=swf,500,375]{$mm[0]}[/media]", $str);
                        continue;
                    }
                }
                $str = str_replace($nn[0][$i], "", $str);
            }
        }
        $str = preg_replace("/<SCRIPT\b[^<>]*>.*(<\/\s*script\s*\/?>|$)/Uisx", "", $str);
        $str = preg_replace("/<select\b[^<>]*>.*(<\/\s*select\s*\/?>|$)/Uisx", "", $str);
        $str = preg_replace("/<\/?br\s*\/?>|&lt;\/br\s*\/?&gt;/Uisx", "\r\n", $str);
        $str = preg_replace("/<style\b[^<>]*>.*<\/\s*style\s*\/?>/Uisx", "", $str);
        $str = preg_replace("/<img[^<>]*src=\"[^<>]*\"[^<>]*file=\"([^<>]*)\"[^<>]*>/Uisx", "<img src=\"\\1\">", $str);
        //$str = preg_replace("/(?<![=\"\'\]\[\,])(http\:\/\/[^<>]*\.(jpg|gif|png))/Uisx", "<img src=\"\\1\">", $str);
        $str = preg_replace("/([0-9]{4}\-[0-9]{1,2}\-[0-9]{1,2}|(半|[0-9])(小时|天)前)[^<>]*下载附件[^<>]*KB\)/", "", $str);
        //$str = stripcslashes($str);
        return $str;
    }
}

if (!function_exists("my_array_max")) {
    function my_array_max($arr)
    {
        if (!empty($arr)) {
            foreach ($arr as $key => $value) {
                if (!isset($max) || ($max < $value)) {
                    $max = $value;
                    $max_key = $key;
                }
            }
        } else {
            return 0;
        }
        return $max_key;
    }
}

function unicode_encode1($name)
{
    $name = iconv('GB2312', 'UCS-2', $name);
    $len = strlen($name);
    $str = '';
    for ($i = 0; $i < $len - 1; $i = $i + 2) {
        $c = $name[$i];
        $c2 = $name[$i + 1];
        if (ord($c) > 0) {
            $str .= '\u' . base_convert(ord($c), 10, 16) . base_convert(ord($c2), 10, 16);
        } else {
            $str .= $c2;
        }
    }
    return $str;
}

function cn2utf8($str)
{
    if (!is_utf8($str)) {
        $str = iconv("GB2312", "UTF-8//IGNORE", $str);

    }
    return $str;
}


function utf82cn($name)
{
    $tostr = "";
    if (is_utf8($name)) {
        for ($i = 0; $i < strlen($name); $i++) {
            $curbin = ord(substr($name, $i, 1));
            if ($curbin < 0x80) {
                $tostr .= substr($name, $i, 1);
            } elseif ($curbin < bindec("11000000")) {
                $str = substr($name, $i, 1);
                $tostr .= "&#" . ord($str) . ";";
            } elseif ($curbin < bindec("11100000")) {
                $str = substr($name, $i, 2);
                $tostr .= "&#" . GetUnicodeChar($str) . ";";
                $i += 1;
            } elseif ($curbin < bindec("11110000")) {
                $str = substr($name, $i, 3);
                $gstr = iconv("UTF-8", "GB2312//IGNORE", $str);
                //$gstr= iconv("UTF-8","GBK",$str);
                if (!$gstr) {
                    $tostr .= "&#" . GetUnicodeChar($str) . ";";
                } else {
                    $tostr .= $gstr;
                }

                $i += 2;
            } elseif ($curbin < bindec("11111000")) {
                $str = substr($name, $i, 4);
                $tostr .= "&#" . GetUnicodeChar($str) . ";";

                $i += 3;
            } elseif ($curbin < bindec("11111100")) {
                $str = substr($name, $i, 5);
                $tostr .= "&#" . GetUnicodeChar($str) . ";";

                $i += 4;
            } else {
                $str = substr($name, $i, 6);
                $tostr .= "&#" . GetUnicodeChar($str) . ";";

                $i += 5;
            }
        }
        return $tostr;
    } else {
        return $name;
    }
}

function GetUnicodeChar($str)
{
    $temp = "";
    for ($i = 0; $i < strlen($str); $i++) {
        $x = decbin(ord(substr($str, $i, 1)));
        if ($i == 0) {
            $s = strlen($str) + 1;
            $temp .= substr($x, $s, 8 - $s);
        } else {
            $temp .= substr($x, 2, 6);
        }
    }
    return bindec($temp);
}

function is_utf8($str)
{
    if (preg_match("/\\\u[0-9a-z]{4}/i", $str)) {
        return true;
    }
    $c = 0;
    $b = 0;
    $bits = 0;
    $len = strlen($str);
    for ($i = 0; $i < $len; $i++) {
        $c = ord($str[$i]);
        if ($c > 128) {
            if (($c >= 254)) return false;
            elseif ($c >= 252) $bits = 6;
            elseif ($c >= 248) $bits = 5;
            elseif ($c >= 240) $bits = 4;
            elseif ($c >= 224) $bits = 3;
            elseif ($c >= 192) $bits = 2;
            else return false;
            if (($i + $bits) > $len) return false;
            while ($bits > 1) {
                $i++;
                $b = ord($str[$i]);
                if ($b < 128 || $b > 191) return false;
                $bits--;
            }
        }
    }
    return true;
}


function quanurl2($subUrl, $wurl, $baseurl = "")
{
    if (is_string($subUrl)) $subUrl = urldecode($subUrl);
    if (is_array($subUrl) || $subUrl == "") return "";
    preg_match("/(https?)\:\/\//Uisx", $wurl, $nn);
    $https = $nn[1];
    $baseurl = preg_replace("/(https?\:\/\/[^\/]+)$/Uisx", "\\1/", $baseurl);
    if (!preg_match("/(https?\:\/\/[^\/]+)$/Uisx", $baseurl)) {
        $baseurl = "";
    }
    $subUrl = str_replace('\\', "/", trim($subUrl));
    $subUrl = str_replace('&amp;', "&", $subUrl);
    $subUrl = preg_replace("/^\.\?/", "?", $subUrl);
    $wurl = ($baseurl) ? $baseurl : $wurl;
    $wurl = preg_replace("/\?.*$/Uisx", "", $wurl);
    preg_match_all("/(https?\:\/\/([^\/]*?))(.*)$/Uimx", $wurl, $mm);
    $host = $mm[2][0];
    $subUrl = preg_replace("/^\/\//", $https . "://", $subUrl);
    if (substr($subUrl, 0, 7) == "http://" || substr($subUrl, 0, 8) == "https://") {
        $newurl = $subUrl;
    } elseif (preg_match("/^\//", $subUrl)) {
        $newurl = "{$https}://" . $host . $subUrl;
    } elseif (preg_match("/^\.\.\//", $subUrl)) {
        $tmsuburl = $subUrl;
        $tempparentUrl = $wurl;
        preg_match_all("/(\.\.\/)/Uisx", $subUrl, $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            $tmsuburl = preg_replace("/^\.\.\//", "", $tmsuburl);
            if (!preg_match("/https?\:\/\/[^<>\/]+\/?$/Uisx", $tempparentUrl)) {
                $tempparentUrl = preg_replace("/(?!<\/)\/[^<>\/]*\/[^<>\/]*$/", "/", $tempparentUrl);
            }
        }
        $newurl = preg_replace("/\/$/", "", $tempparentUrl) . "/" . $tmsuburl;
    } elseif (preg_match("/^[^\.\/\?]/", $subUrl)) {
        preg_match("/^(.*)\//Uisx", $subUrl, $nna);
        preg_match("/https?\:\/\/.*\/(.*)\//Uisx", $wurl, $nnb);
        if ($nnb[1] == $nna[1]) {
            $newurl = $https . "://" . $host . "/" . $subUrl;
        } else {
            $newurl = dirname2($wurl) . "/" . $subUrl;
        }
    } elseif (preg_match("/^\?/", $subUrl)) {
        $newurl = preg_replace("/\?.*$/U", "", $wurl) . $subUrl;
    } else {
        $newurl = preg_replace("/\/[^\/]*$/", "/", $wurl) . $subUrl;
    }
    $newurl = preg_replace("/\/\.\//", "/", $newurl);
    $newurl = preg_replace("/\/https?\:\//", "/", $newurl);
    $newurl = preg_replace("/[\r\n]/", "", $newurl);
    $newurl = preg_replace("/(?<!http\:)\/{2,}/", "/", $newurl);
    $newurl = preg_replace("/(https?\:)\/{1,}/", "\\1//", $newurl);
    return $newurl;
}


function dquanurl2($nr, $wurl, $baseurl)
{
    $nr = preg_replace("/(src|location|<link[^>]*href|<EMBED[^>]*VALUE|action|background|imgurl|<PARAM\s+NAME\=movie\s+VALUE|href)\s*=\s*(\"|\')?([^\"\'\>\s]+)(\\2|(?=\>)|\s)/Uisxe", "'\\1=\"'.quanurl('\\3','$wurl',\"$baseurl\").'\"'", $nr);
    $nr = preg_replace("/url\((\"|'|)?([^<>\s\"']+)\\1\)/Uisxe", '"url(".quanurl("\\2",$wurl).")"', $nr);
    //$nr=stripCSlashes($nr);
    return $nr;
}

if (!function_exists("host")) {
    function host($str)
    {
        $str = urldecode($str);
        preg_match_all("/https?\:\/\/(?:[^<>\/]*?)([a-z0-9_\-]+?\.(?:com|gov|edu|org|mobi|la|us|hk|tw|net|cn|vn|cc|info|top|vip|co|site|me|xyz|or|id)(?:(?:\.net|\.cn|\.cc|\.tv|\.hk|\.tw|\.info|\.vn|\.top|\.vip|\.cn(?=\/|$|\:)|\.bn|\.sg|\.my|\.th|\.id|\.lo|\.vn|\.uk|\.mm|\.la|\.ph|\.kh)*(?=\:|\/|$)))/isx", $str, $nn);
        $host = $nn[1][0];
        $host = preg_replace("/^(?:[^<>]*\.)*([a-z0-9_\-]+(?:\.(?:com|gov|edu|org|mobi|la|us|hk|tw|net|cn|vn|cc|info|top|vip|co|site|me|xyz|or|id))?\.(com|gov|edu|org|cn|mobi|la|hk|tw|us|cc|info|vn|top|vip|co|site|me|xyz|bn|sg|my|th|lo|id|uk|la|ph|mm|kh))/Uisx", "\\1", $host);
        if ($host == "" && preg_match("/https?\:\/\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", $str, $nn)) {
            $host = $nn[1];
        }
        return $host;
    }
}
if (!function_exists("wwwhost")) {
    function wwwhost($str)
    {
        $str = urldecode($str);
        preg_match_all("/https?\:\/\/([^<>\/]*)/isx", $str, $nn);
        $host = $nn[1][0];
        return $host;
    }
}



function clmh($str)
{
    $str = preg_replace("/(\r|\n)+$/Uisx", "", trim($str));
    $str = preg_replace("/(\r|\n)+/m", "\\r\\n", trim($str));
    $str = preg_replace("/\"/m", "\\\"", trim($str));
    $str = preg_replace("/\&amp\;/m", "&", trim($str));
    return $str;
}

function droppagetablediv($nr, $nextpagere = "", $bug = 0)
{
    if (!is_utf8($nextpagere)) $nextpagere = u($nextpagere);
    if (preg_match("/下一页|下页|上一页|上页|前一页|首页/", $nr)) {
        $re = ".*(?<![^\<\>a-z0-9_\s])(下一页|下页|上一页|上页" . $nextpagere . ").*";
        $nr = preg_replace("/<p[^<>]*>{$re}(<\/p>|(?:<\/(td|th|div)))/Uisx", "", $nr);
        $nr = preg_replace("/\[url[^<>\[\]]*\](\s|&nbsp;)*(上一页|下一页|上页|下页)(\s|&nbsp;)*\[\/url[^<>\[\]]*\]/Uisx", "", $nr);
        $nr = @preg_replace("/(<br>|<p[^<>]*>|\s)*<table[^<>]*>{$re}<\/table>/Uisx", "", $nr);
        $nr = @preg_replace("/(<br>|<p[^<>]*>|\s)*&lt;table[^<>]*&gt;{$re}&lt;\/table&gt;/Uisx", "", $nr);
        $nr = @preg_replace("/(<br>|<p[^<>]*>|\s)*<div[^<>]*>{$re}<\/div>/Uisx", "", $nr);
        $nr = @preg_replace("/(<br>|<p[^<>]*>|\s)*&lt;div[^<>]*&gt;{$re}&lt;\/div&gt;/Uisx", "", $nr);
        $nr = preg_replace("/\[b\](\s*上一页\s*)?[0-9\s]+(\s*下一页\s*)\[\/b\]/Uisx", "", $nr);
        $nr = preg_replace("/(上一页|上页)?[0-9]+(下页|下一页)/Uisx", "", $nr);
        $nr = preg_replace("/前一页|首页/Uisx", "", $nr);
    }
    return $nr;
}


function mustzw($str)
{
    preg_match_all("/([\x{4e00}-\x{9fa5}A-Za-z0-9_]+)/uisx", $str, $nn);
    return $nn[1][0];
}

//通杀
function tongx($str, $nr, $isint = 0)
{
    $mm = preg_split("/,|\;/", $str);
    $arr = array();
    foreach ($mm as $one) {
        //for($i=0;$i<count($mm);$i++){
        if (trim($one) == "") continue;
        $isints = ($isint) ? "0-9\," : "^<>";
        switch ($isint) {
            case 1:
                $isints = "0-9\,";
                $u = "";
                break;
            case 2:
                $isints = "\x{4e00}-\x{9fa5}A-Za-z0-9_\'\\\"";
                $u = "u";
                break;
            default:
                $isints = "^<>";
                $u = "";
        }

        $re = "/" . chakai($one) . "(?:\:|：|：| | |<\/?(?:strong|b|a|font|td|th|span|th|em|li|span|i)[^<>]*>|\&nbsp\;| |　)+?([" . $isints . "]+?)/Uisu";
        try {
            if (preg_match_all($re, $nr, $nn)) {
                foreach ($nn[1] as $onn) {
                    if (trim($onn) != "") {
                        $arr[] = clwz($onn);
                    }
                }
            }
        } catch (\Exception $e) {
            echo "正则表达式执行失败: ". $e->getMessage();
        }




        $re = "/(?:<\/?(?:strong|b|a|font|td|span|th|em|li)[^<>]*>|\&nbsp\;| |　)([0-9\,]+?)(?:<\/?(?:strong|b|a|font|td|span|th|em|li|i)[^<>]*>|\&nbsp\;|\s)*" . chakai($one, 1) . "(?![\x{4e00}-\x{9fa5}A-Za-z0-9_]|\)|\,|，|。)/Uuis";
        //echo $re."\r\n";

        if (function_exists('mb_ereg_match_all')) {
            mb_regex_encoding('UTF-8');
            mb_ereg_match_all($re, $nr, $nn);
        }else {
            try {
                if (preg_match_all($re, $nr, $nn)) {
                    foreach ($nn[1] as $onn) {
                        if (trim($onn) != "") {
                            $arr[] = clwz($onn);
                        }
                    }
                }
            } catch (Exception $e) {
                console.error("正则表达式出错");
            }

        }


        $re = "/<META\s+name=\\\"" . chakai($one) . "\\\"\s+content=\\\"([^<>]*)\\\">/Uis";
        if (@preg_match_all($re, $nr, $nn)) {
            foreach ($nn[1] as $onn) {
                if (trim($onn) != "") {
                    $arr[] = clwz($onn);
                }
            }
        }
    }


    $return = "";
    foreach ($arr as $oarr) {
        if (strlen($oarr) > strlen($return)) {
            $return = $oarr;
        }
    }
    return $return;
}

function guolv($str)
{
    if (preg_match("/来源|字体|大小|责编|颜色|作者|责任编辑/", $str)) {
        return "";
    }
    return $str;
}

function chakai($str, $nowei = 0)
{
    //$str=addsla($str);
    if (!isutf8($str)) {
        $str = preg_replace("/([" . chr(0xb0) . "-" . chr(0xf7) . "][" . chr(0xa1) . "-" . chr(0xfe) . "])/", "\\1(?:\s| |\&nbsp\;|<(?:span|b|strong)[^<>]*>(?:<\/?(?:span|b|strong)>)?)*", $str); //GBK
    } else {
        $str = preg_replace("/([\u4E00-\u9FA5\uF900-\uFA2D])/u", "\\1（?>(?:\s| |\&nbsp\;|<(?:span|b|strong)[^<>]*>(?:<\/?(?:span|b|strong)>)?)*)", $str); //utf8
    }
    if ($nowei) {
        $str = substr($str, 0, strlen("(?>(?:\s| |\&nbsp\;|<(?:span|b|strong)[^<>]*>(?:<\/?(?:span|b|strong)>)?)*)") * (-1));
    }
    return $str;
}

function addsla3($yy)
{
    $restr = str_replace("\\", "\\\\\\", $yy);
    $restr = str_replace(".*", "allall", $yy);
    $restr = str_replace(".", "\.", $restr);
    $restr = preg_replace("/\\\$/Uisx", "\\\\\\\\\\\\$", $restr);
    $restr = preg_replace("/\"/Uisx", "\\\"", $restr);
    $restr = preg_replace("/\-/Uisx", "\\-", $restr);
    $restr = preg_replace("/\:/Uisx", "\\:", $restr);
    $restr = preg_replace("/\?/Uisx", "\\?", $restr);
    $restr = preg_replace("/\//Uisx", "\\/", $restr);
    $restr = preg_replace("/\{/Uisx", "\\{", $restr);
    $restr = preg_replace("/\}/Uisx", "\\}", $restr);
    $restr = preg_replace("/\(/Uisx", "\\(", $restr);
    $restr = preg_replace("/\)/Uisx", "\\)", $restr);
    $restr = preg_replace("/\|/Uisx", "\\|", $restr);
    $restr = preg_replace("/\,/Uisx", "\\,", $restr);
    $restr = preg_replace("/\!/Uisx", "\\!", $restr);
    $restr = preg_replace("/\^/Uisx", "\\^", $restr);
    $restr = preg_replace("/\*/Uisx", ".*", $restr);
    $restr = preg_replace("/\#/Uisx", "\\#", $restr);
    $restr = preg_replace("/\]/Uisx", "\\]", $restr);
    $restr = preg_replace("/\[/Uisx", "\\[", $restr);
    $restr = preg_replace("/\+/Uisx", "\\+", $restr);
    $restr = preg_replace("/((\\s\+)?(\\n)?\\s)+/m", "\\\s+", $restr);
    $restr = preg_replace("/MMM$/Uisx", "", $restr);
    $restr = preg_replace("/\\\\s\+MMM\\\\s\+/", "[\s\\n]+", $restr);
    $restr = str_replace("allall", ".*", $restr);
    return $restr;
}


if(!function_exists('clwz')) {
    function clwz($str)
    {
        $str = trim(preg_replace("/<a((?<=!thread_subject).)*>.*<\/a>/Uisx", "", strip_tags($str, "<a>")));
        $str = preg_replace("/\'(.*)\'.*$/Uisx", "\\1", $str);
        $str = preg_replace("/'|\"|\\\\\"|null|【|】|：|\:/Uisx", "", $str);
        $str = preg_replace("/(^|>)([\r\n\t \x{3000}]|\&nbsp\;)*/u", "\\1", $str);
        $str = strip_tags($str);
        return $str;
    }
}


function cltitle($str)
{
    $str = strip_tags($str);
    $str = preg_replace("/\\\'/Uisx", "'", $str);
    $str = preg_replace("/\\\\\"/Uisx", '"', $str);
    if(preg_match("/^\"(.*)\"$/Uisx",$str,$nn)){
        $str=stripcslashes($nn[1]);
    }
    return $str;
}

function htmltotxt($str, $n = 0, $thisurl = "", $thisbaseurl = "", $lie_a = false, $keeptable = 0)
{
    global $rs;
    $str = trim($str);
    $str = strip_tags2($str, "strong|b|a|p|img|br|td|th|table|tr|ul|li|span|hr|center|em|font", $lie_a);
    //$str=preg_replace("/\"/", "\\\"",$str);
    preg_match_all("/<img(.*)(?<!width|height|\=|\.|width\s)>/Uisx", $str, $nn00);
    for ($i = 0; $i < count($nn00[1]); $i++) {
        $tmp = preg_replace("/\\\(?!\'|\")/", "/", $nn00[0][$i]);
        preg_match_all("/file\s*\=\s*\\\?\"([^<>]*)\\\??\"/Uisx", $tmp, $nnn3);
        $src = trim($nnn3[1][0]);
        if ($src == "") {
            preg_match_all("/original\s*\=\s*\\\?\"([^<>]*)\\\??\"/Uisx", $tmp, $nnn2);
            $src = trim($nnn2[1][0]);
        }
        if ($src == "") {
            preg_match_all("/(?:real_src|data-lazyload-src|data-original|crs|src[0-9]+)\s*\=\s*\\\?\"([^<>]*)\\\??\"/Uisx", $tmp, $nnn2);
            $src = trim($nnn2[1][0]);
        }
        if ($src == "") {
            preg_match_all("/src[0-9\s]*\=[\s\\\?\"\']*?([^<>\\\'\"]*)((?<=jpeg|png|gif|jpg)\s|'|\"|>|$)/Uisx", $tmp, $nnn2);
            $src = trim($nnn2[1][0]);
        }
        if ($rs['loadimg'] == 1) {
            $str = str_replace($nn00[0][$i], "\r\n[img]http://collect.longsunhd.com/source/plugin/yzs1013_pldr/getimg.php?url=" . surlencode(quanurl(trim($src), $thisurl, $thisbaseurl)) . "[/img]\r\n<p>\r\n", $str);
        } else {
            $str = str_replace($nn00[0][$i], "\r\n&nbsp;\r\n[img]" . quanurl(trim($src), $thisurl, $thisbaseurl) . "[/img]\r\n<p>\r\n&nbsp;\r\n", $str);
        }
    }
    $str = preg_replace("/\&ldquo\;/Uisx", "\"", $str);
    $str = preg_replace("/\&rdquo\;/Uisx", "\"", $str);
    $str = preg_replace("/<(\/?)center>/isx", "[\\1align=center]", $str);
    $str = preg_replace("/\[\/align=center\]/isx", "[/align]", $str);
    $str = preg_replace_callback("/<p\s*[^<>]+align\s*=[\"']?\s*(center|left|right)[^<>]*>(.*)<\/p>/Uisx", function ($em) {
        $em[2] = preg_replace("/<(b|strong|em|td|th|span|font)[^<>]*color=[\"\']?([^<>\"\'\s]*)[^<>]*>(.*)<\/\\1>/i", "[color=\\2]\\3[/color]", $em[2]);
        $em[2] = preg_replace("/<(b|strong|em|td|th|span|font)[^<>]*color:\s*([^\"\'\;\s]*?)[^<>]*>(.*)<\/\\1>/Uisx", "[color=\\2]\\3[/color]", $em[2]);
        $em[2] = preg_replace("/<(\/?)(b|strong|em)/i", "[\\1\\2]", $em[2]);
        return "[align={$em[1]}]{$em[2]}[/align]";
    }, $str);
    $str = preg_replace_callback("/<p\s*[^<>]+text\-align\:\s*(center|left|right)[^<>]*>(.*)(<\/p>|(?=<p))/Uisx", function ($em) {
        $em[2] = preg_replace("/<(b|strong|em|td|th|span|font)[^<>]*color=[\"\']?([^<>\"\'\s]*)[^<>]*>(.*)<\/\\1>/i", "[color=\\2]\\3[/color]", $em[2]);
        $em[2] = preg_replace("/<(b|strong|em|td|th|span|font)[^<>]*color\:([^<>\;\s]*?)[^<>]*>(.*)<\/\\1>/i", "[color=\\2]\\3[/color]", $em[2]);
        $em[2] = preg_replace("/<(\/?)(b|strong|em)/i", "[\\1\\2]", $em[2]);
        return "[align={$em[1]}]{$em[2]}[/align]";
    }, $str);
    $str = preg_replace("/<(\/?)\s*(br|p)[^<>]*>/isx", "\r\n", $str);
    $str = preg_replace("/(\r\s*\n)+/m", "\r\n", $str);
    if (!$keeptable) {
        $str = preg_replace("/<(\/?)(td|th|table|tr|li|ul)\b([^<>]*)>/Uisx", "", $str);
    }
    $str = preg_replace("/\[img\][^<>\[\]]*Array\[\/img\]/Usx", "", $str);
    $str = preg_replace("/^\s*　　\s*(http\:\/\/[^<>]*\.jpg)\s*$/Uixm", "\r\n　　[img]\\1[/img]\r\n", $str);
    if (!function_exists('callbackfun01')) {
        function callbackfun01($em)
        {
            global $thisurl, $thisbaseurl;
            if (trim(strip_tags(preg_replace("/\&nbsp\;/Uisx", "", $em[2]))) != "") {
                if (preg_match("/\[img\].*\[\/img\]/Uisx", $em[2])) {
                    return trim(strip_tags($em[2]));
                } else {
                    return "[url=" . quanurl(trim(strip_tags($em[1])), $thisurl, $thisbaseurl) . "]" . trim(strip_tags($em[2])) . "[/url]";
                }
            } else {
                return "";
            }
        }
    }
    $str = preg_replace_callback("/<a[^<>]*href=['\"]([^<>]+)['\"][^<>]*>(.*)<\/a>/Uisx", "callbackfun01", $str);
    //$str = preg_replace("/([\r\n](\s|　)*[\r\n])+/im", "\r\n", $str);
    //$str = preg_replace("/^(　)*(.*)$/ime", '"\r\n　　".trim("\\2").""', $str);
    //$str = preg_replace("/\&[a-z]+\;/isx", "", $str);
    $str = preg_replace("/(。|；|？)(　|\s)+(?![^\r\n]*\[\/img\])/Uisx", "\\1\r\n　　", $str);
    $str = preg_replace("/" . g("(。|；|？)(　|\s)+(?![^\r\n]*\[\/img\])") . "/Uisx", "\\1\r\n　　", $str);
    $str = trim(preg_replace("/^(　|\s|\&nbsp\;)*$/Uisx", "\r\n　　", $str));
    $str = str_replace('\"', '"', $str);
    return trim($str);
}

function getre($host, $fieldname = "nr", $gather_type = 1, &$t = null)
{
    if ($t == null) $t = new t();
    $rs = $t->sqlone("select * from longzs_re where host='" . trim($host) . "' ORDER BY updatetime DESC");
    return $rs;
}

function cookierk($cookie, $id)
{
    $t = new t();
    $t->sql("update longzs_re set cookie='" . trim($cookie) . "' where id=$id");
}

function qz($re, $nr = "")
{
    preg_match_all("/" . trim($re) . "/Uisx", $nr, $nn);
    return $nn[1][0];
}


function redo($url, &$secexe = 0, $soucere = "", $mbre = "", $starti = 0, $endi = 0, $sameurlre = "\/([^<>\/]*)\/[^<>\/]*$")
{
    global $news2, $oldurl;
    static $leiji, $setin;
    $url=quanurl($url,$oldurl);
    if($url!=$GLOBALS['oldredourl']){
        $GLOBALS['oldredourl']=$url;
    }else{
        bug("redo",array("url"=>$url));
        return "";
    }
    bug("redo",array("url"=>$url));
    $leiji = ($leiji == "") ? 0 : $leiji;
    $str = "";
    $oldnr = "";
    $url2 = "";
    jsstart();
    preg_match("/{$sameurlre}/Uisx", $url, $nn);
    if ($setin != $nn[1][0] && $setin != "") return "";
    $setin = $nn[1][0];
    for ($i = $starti; $i <= $endi; $i++) {
        $url2 = $url;
        if ($soucere != "" && $mbre != "") {
            $url2 = preg_replace("/" . $soucere . "/Uisx", preg_replace("/%1/Uisx", $i, $mbre), $url2);
        }
        if ($url2 == $oldurl && $url2 == "") {
            $str = "";
            break;
        } else {
            $oldurl = $url2;
        }
        if (ceil(js()) > 30 || $leiji > 40) return $str;
        $leiji++;
        $news2 = new Zqnews($url);
        $ynr = $news2->getnr();
        $secexe = $news2->secexe;
        $GLOBALS['title'] = cltitle($news2->getbt());
        $str .= "\r\n" . $ynr;
        while ($news2->nextPage != "") {
            $news2->seturl($news2->nextPage);
            $nr = $news2->getnr();
            bug("redo",array("url"=>$news2->nextPage,"redonr"=>$nr));
            $str .= "\r\n" . $nr;
        }
        //$nr = (!is_utf8($nr)) ? u($nr) : $nr;
        if (!strcmp($str, $oldnr)) {
            break;
        } else {
            $oldnr = $str;
        }
    }
    $str = preg_replace("/\[align=center\]\[\/align\]/", "", $str);
    bug("redo",array("url"=>$url,"redonr"=>$ynr));
    if ($news2->textarea != "") {
        $news2->textarea=$str;
        return $news2;
    } else {
        return $str;
    }

}


function strip_tags2($str, $s, $lie_a = false)
{
    if (!function_exists('cbfun91')) {
        function cbfun91($nn)
        {
            return $nn[1] . "=\"" . strip_tags3($nn[2]) . "\"";
        }
    }
    $str = preg_replace_callback("/(desc|alt)=\"(.*)\"/Uisx", "cbfun91", $str);

    if ($lie_a) {
        $str = preg_replace("/<(?!\/|" . $s . "|script|b|strong|a\b)[^<]*(?<!width|height|\=|\.|width\s)>/Uisx", "", $str);
        $str = preg_replace("/<\/(?!" . $s . "|script|b|strong|a\b)[^<]*(?<!width|height|\=|\.|width\s)>/Uisx", "", $str);
    } else {
        $str = preg_replace("/<(?!\/|" . $s . "|script|b|strong)[^<]*(?<!width|height|\=|\.|width\s)>/Uisx", "", $str);
        $str = preg_replace("/<\/(?!" . $s . "|script|b|strong)[^<]*(?<!width|height|\=|\.|width\s)>/Uisx", "", $str);
    }
    return $str;

}

function strip_tags3($str)
{
    $str = preg_replace("/\&lt\;.*\&gt\;/Uisx", "", $str);
    return $str;

}


function addsla2($str, $args = array())
{
    $nn = preg_split("/@@/", $str);
    $n = 0;

    do {
        preg_match_all("/.*?(\(\.\*\)|\(\.\+\)|\(\[\^\<\>\]\*\)|\\\\\\/|\(\[[<>\+\\\-_a-z\%\/0-9\^\$]+\]\*\)|\:y\b|\:nn[0-9]+?|\.\*|\[[<>\+\\\-_a-z\%\/0-9\^\$]+\]|\[0\-9\]|\{标题\}|\{内容\}|\{变量[0-9]+\}|\\\"|\\\(|\\\)|\\\'|\\\s+|\\\r|\\\n|\+|\*|\\\$|\\\^)/isx", trim($nn[0]), $mm);
        $replace_times = 1;
        $nn[0] = str_replace($mm[1][0], "&&" . $n . "&&", $nn[0], $replace_times);
        $GLOBALS['arr'][$n] = $mm[1][0];
        $n++;
    } while (count($mm[1]) > 0 && $n < 5);
    $nn[0] = addsla($nn[0]);
    if (!function_exists('cbfun2')) {
        function cbfun2($it)
        {
            return $GLOBALS['arr'][$it[1]];
        }
    }
    $nn[0] = preg_replace_callback("/&&([0-9]+)&&/Uisx", "cbfun2", $nn[0]);
    $nn[0] = str_replace("\\", "\\\\", $nn[0]);
    if (count($nn) == 1) {
        return $nn[0];
    } else {
        return $nn[0] . "@@" . $nn[1];
    }
    unset($GLOBALS['arr']);
}

function jcre($txt, $args = array())
{
    extract($args);
    if (substr(trim($txt), 0, 1) == "." || substr(trim($txt), 0, 1) == "#" || preg_match("/^(div\b|a\b|span\b|p\b|li\b|em\b|h[0-9]+|td\b|th\b|tr\b|strong\b)/Uisx", trim($txt))) {
        return $txt;
    }

    preg_match_all("/^(.*)$/Uimx", $txt, $nn);
    for ($i = 0; $i < count($nn[1]); $i++) {
        $dd = preg_split("/@@|\:nn[0-9]/", $nn[1][$i]);
        $ynn[1][$i] = $dd[0];
        if (preg_match("/\]\*|\]\+|\)\*|\)\+/", $dd[0])) {
            continue;
        }
        if (preg_match("/^([a-zA-Z0-9_\-\/\.]+\.(jpg|gif|png))$/Uisx", $dd[0], $nn33)) {
            $dd[0] = "\[img\][^<>\[\]]*" . addsla($nn33[1]) . "\[\/img\]";
            $txt = str_replace(trim($ynn[1][$i]), trim($dd[0]), $txt);
        }
        if(preg_match("/@'(.*)'/Uisx", $dd[0], $nn22)) {
            $dd[0] = str_replace($nn22[0], "baoliu", $dd[0]);
            $dd[0] = preg_replace("/(\.|。|" . g("。") . "|\*){3,}/", "(.*)", $dd[0]);
            $dd[0] = preg_replace("/[\^\,]{3,}/", "([^<>]*)", $dd[0]);
            $dd[0] = preg_replace("/(?<![0-9])0{3,}/", "([^<>]*)", $dd[0]);
            if (preg_match("/((?:style|class|id)=[a-zA-Z0-9\-_\s\"\']+)(\([^\s]+\))((?:style|class|id)=[a-zA-Z0-9\-_\s\"\']+)/isx", $dd[0], $nn55)) {
                $nn55[1] = str_replace("\"", "[\\\"']?", stripslashes(addsla2($nn55[1])));
                $nn55[3] = str_replace("\"", "[\\\"']?", stripslashes(addsla2($nn55[3])));
                $dd[0] = "<[^<>]*{$nn55[1]}[^<>]*>{$nn55[2]}<[^<>]*{$nn55[3]}[^<>]*>";
                $txt = str_replace(trim($ynn[1][$i]), trim($dd[0]), $txt);
                $txt = str_replace("baoliu", $nn22[0], $txt);
                return $txt;
            }
            if (preg_match("/(?<!\\\)\"|\s|(?<!\\\)\//Uis", trim($dd[0])) || preg_match("/[\^\,\.\*]{4,}/Uisx", $ynn[1][$i])) {
                $dd[0] = preg_replace("/\"/Uisx", "\\\"", $dd[0]);
                $txt = str_replace(trim($ynn[1][$i]), stripslashes(addsla2(trim($dd[0]))), $txt);
            }
            $txt = str_replace("baoliu", $nn22[0], $txt);
            $txt = preg_replace("/>{3,}/", ".*", $txt);
            $txt = preg_replace("/<{3,}/", "[^<>]", $txt);
        }
    }
    return $txt;
}

function addsla0($str)
{
    $str = str_replace('\\', '\\\\\\\\', $str);
    return $str;
}


function striponexg($str)
{
    $str = str_replace('\\', "&&&&", $str);
    $str = preg_replace("/\\\/", "", $str);
    $str = preg_replace('/&&&&/', "\\", $str);
    return $str;
}

function istextarea($str)
{
    if (preg_match("/\。|，|“|：|\&nbsp\;|<img/Uisx", $str) || strlen($str) > 100) {
        return true;
    }
    return false;
}

function file_get_content($durl, $cookie2 = "", $Referer = "", $header = 1, $proxy = "")
{
    return file_get_contents($durl);
}

//==curl
function curl_file_get_contents($durl, $cookie2 = "", $Referer = "", $header = 1, $proxy = "", $re_id = 0, $rs = array())
{
    static $oldurl, $oldcookie;
    global $cookie,$c;
    //抓网页 curl_file_get_contents
    if($c==null){
        $GLOBALS['mycurl']=$c=new Mycurl();
        $c->result("",$durl,1);
    }
    if(preg_match("/^http/Uisx",$durl)) $durl = csurlencode($durl);
    if (preg_match("/security_verify_data=/i", $durl)) {
        $durl = preg_replace("/security_verify_data=([^&]+)?/Uixs", "security_verify_data=313638302c31303530", $durl);
    }
    $zz = parse_url($durl);
    $Referer = ($Referer == "") ? $durl : $Referer;
    $cs = 0;
    $r=getdbhostbyurl($durl);
    $cookie=trim($c->cookie);
    if($cookie==""){
        $cookie=$r['cookie'];
    }
    if(preg_match("/^Post|get/i",$durl)||trim($r['httpheadoption'])!=""){
        if(trim($r['httpheadoption'])!=""){
            $str=$r['httpheadoption'];
        }else{
            $str=$durl;
        }
        $ispost = false;
        if(preg_match("/(POST|GET)\s+([^\s]*)\s+HTTP/Uisx",$str,$nn)) {
            $ispost = (strtoupper($nn[1]) == "POST") ? true : false;
            $durl = $nn[2];
        }
        preg_match("/Referer\:\s*([^\n]*)$/ixm",$str,$nn);
        $Referer=($nn[1])?trim($nn[1]):$Referer;
        preg_match("/Cookie\:\s*([^\n]*)$/ixm",$str,$nn);
        $cookie=($cookie)?$cookie:$nn[1];
        preg_match("/(^.*)(?:\r\n\r\n|\n\n)(.*?)$/Uis", $str, $nn);
        if (isset($nn[2])) {
            $postdata = trim($nn[2]);
        } else {
            $postdata = '';
        }
        $rs['httpheadoption']=guolvpoststr($str,$postdata);
    }

    $data=array();
    do {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $durl);


        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0');
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Accept: */*',
            'Content-Type: application/x-www-form-urlencoded',
        ));
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        if ($proxy != "") {
            curl_setopt($ch, CURLOPT_PROXY, $proxy);
        }
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        if ($Referer != "" && $Referer != "http://"&& $Referer != "https://"&&!$c->zqsetreferernull) {
            curl_setopt($ch, CURLOPT_REFERER, $Referer);
        }
        if ($cookie != ""&&!$c->zqsetcookienull) {
            curl_setopt($ch, CURLOPT_COOKIE, trim($cookie));
        }

        if ($ispost) {
            curl_setopt( $ch, CURLOPT_POST, true );
            curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata);
        }

        if (is_string($rs['httpheadoption'])&&trim($rs['httpheadoption']) != "") {
            curl_setopt($ch, CURLOPT_HTTPHEADER, httpheadertoarray($rs['httpheadoption']));
        } elseif(is_array($rs['httpheadoption'])) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $rs['httpheadoption']);
        } else {
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Host:' . $c->qhost,
                'Content-Type: application/x-www-form-urlencoded',
                'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0',
                'Connection:  keep-alive', 'Accept:  text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Accept-Language:  en-US,en;q=0.9,zh-CN,zh;q=0.8,zh;q=0.7,zh-TW;q=0.7,zh-HK;q=0.5,ja;q=0.6,bg;q=0.5',
            ));
        }
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
        $r = curl_exec($ch);
        $request_header = getCurlHeader($ch,$data,$durl);
        tishi($durl);
        $a = curl_getinfo($ch,CURLINFO_HTTP_CODE);
        $c->httpCode = $a;
        curl_close($ch);

        if(preg_match_all("/^location\:\s*(http.*)$/mi",$r,$ll)){
            $durl=trim(end($ll[1]));
        }
        $isdelcookie=$isdelcookie??"";
        if($a==0&&$cookie!=""&&!$c->zqsetcookienull){
            $cookie="";
            $isdelcookie=1;
            continue;
        }elseif($isdelcookie&&$r!=""){
            $c->setrs("listzq|nrzq",1);
        }
        $c->result($r, $durl);
        $locationjump=$locationjump??"";
        $rs['locationjump']=$rs['locationjump']??"";
        $locationjump = ($rs['locationjump'] == null) ? 1 : 0;

        preg_match("/<title>404\s+Not\s+Found<\/title/Uisx", $r, $nnn);
        if (isset($nnn[0])) {
            $value = $nnn[0];
        } else {
            $value = null;
        }
        if (($value != "" || $c->location != "") && $cs++ < 2 && !$c->haveyzm&&$c->location!=$durl) {
            if ($c->location != ""){
                $durl = $c->location;
                $durl = csurlencode($durl);
            }
            continue;
        }elseif(preg_match("/location\.href\s*=\s*['\"]([^<>\"\']*)/isx",$r,$nn) && !$c->haveyzm&&$c->zqsetloclhrefyes){
            $durl = quanurl($nn[1],$durl);
            $durl = csurlencode($durl);
            continue;
        } else {
            break;
        }
    } while (1);
    fopenwtemp("curl_file_get_contents","\n{$request_header}\n".$c->body."\n\n\n\n",$durl);
    return $c->body;
}

//==curl2
function curlbase($url, $cookie = "", $Referer = "")
{
    static $cookie;
    global $c;
    $host = whost($url);
    $Referer = ($Referer == "") ? $url : $Referer;

    if($c==null){
        $GLOBALS['mycurl']=$c=new Mycurl();
        $c->result("",$url,1);
    }

    //抓网页curlbase
    $timeout = 10;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
    curl_setopt($ch, CURLOPT_HEADER, 1);
    //curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    /*if(preg_match("/multipart/Uisx",$post)){
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=$boundary"));
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    }*/
    if (!$c->zqsetreferernull){
        curl_setopt($ch, CURLOPT_REFERER, $Referer);
    }

    if (trim($c->rs['httpheadoption']) != ""){
        curl_setopt($ch, CURLOPT_HTTPHEADER, httpheadertoarray($c->rs['httpheadoption']));
    } else {
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/x-www-form-urlencoded',
            'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0',
            'Accept:  text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Language:  en-US,en;q=0.9,zh-CN,zh;q=0.8,zh;q=0.7,zh-TW;q=0.7,zh-HK;q=0.5,ja;q=0.6,bg;q=0.5',
            'Connection:  keep-alive',
        ));
    }

    if (!$c->zqsetcookienull){
        if($c->rs['cookie']==""){
            $c->rs['cookie']=getdbhostbyurl($url);
        }
        curl_setopt($ch, CURLOPT_COOKIE, trim($c->rs['cookie']));
    }
    //if ($Querystring != "" && $uu[1][0] == "POST") {
    //    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
    //    curl_setopt($ch, CURLOPT_POSTFIELDS, $Querystring);
    //}

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
    $result = curl_exec($ch);
    $data=array();
    $request_header = getCurlHeader($ch,$data,$url);
    $c->httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
    curl_close($ch);
    if(preg_match_all("/^location\:\s*(http.*)$/mi",$result,$ll)){
        $url=trim(end($ll[1]));
    }
    $c->result($result, $url);
    preg_match("/set\-cookie\:\s*([^\n]*)/m", $result, $nn);
    $cookie = trim($nn[1]);
    preg_match("/(^.*)(?:\r\n\r\n|\n\n)(.*?)$/Uis", $result, $nn);
    $result = $nn[2];
    if (@gzinflate(substr($result, 10))) {
        $result = @gzinflate(substr($result, 10));
    }
    fopenwtemp("curlbase","\n{$request_header}\n:".$result."\n\n\n\n",$url);
    return $result;
}


function curl_file_get_contents2($urlArray)
{
    if (empty($urlArray)) return false;
    $isStr = false;
    if (is_string($urlArray)) {
        $urlArray = array($urlArray);
        $isStr = true;
    }
    $mh = curl_multi_init(); //curl_multi_init --  Returns a new cURL multi handle
    $curlArray = array();
    foreach ($urlArray as $i => $url) {
        $curlArray[$i] = curl_init($url);
        curl_setopt($curlArray[$i], CURLOPT_RETURNTRANSFER, true); //设置为true表示返回抓取的内容，而不是直接输出到浏览器上。TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly
        curl_setopt($curlArray[$i], CURLOPT_AUTOREFERER, true); //自动设置referer。TRUE to automatically set the Referer: field in requests where it follows a Location: redirect.
        curl_setopt($curlArray[$i], CURLOPT_FOLLOWLOCATION, true); //跟踪url的跳转，比如301, 302等
        curl_setopt($curlArray[$i], CURLOPT_MAXREDIRS, 2); //跟踪最大的跳转次数
        curl_setopt($curlArray[$i], CURLOPT_HEADER, 0); //TRUE to include the header in the output.
        curl_setopt($curlArray[$i], CURLOPT_ENCODING, ""); //接受的编码类型,The contents of the "Accept-Encoding: " header. This enables decoding of the response. Supported encodings are "identity", "deflate", and "gzip". If an empty string, "", is set, a header containing all supported encoding types is sent.
        curl_setopt($curlArray[$i], CURLOPT_CONNECTTIMEOUT, 5); //连接超时时间
        curl_setopt($curlArray[$i], CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0");
        curl_multi_add_handle($mh, $curlArray[$i]); //curl_multi_add_handle --  Add a normal cURL handle to a cURL multi handle
    }

    $running = NULL;
    $count = 0;
    do {
        //10秒钟没退出，就超时退出
        if ($count++ > 50) break;
        usleep(50000);
        curl_multi_exec($mh, $running); //curl_multi_exec --  Run the sub-connections of the current cURL handle
    } while ($running > 0);

    $content = array();
    foreach ($urlArray as $i => $url) {
        $content[$url] = curl_multi_getcontent($curlArray[$i]); //curl_multi_getcontent --  Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set
    }

    //curl_multi_remove_handle --  Remove a multi handle from a set of cURL handles
    foreach ($urlArray as $i => $url) {
        curl_multi_remove_handle($mh, $curlArray[$i]);
    }

    //curl_multi_close --  Close a set of cURL handles
    curl_multi_close($mh);
    //如果参数$urlArray是字符串，则将返回值也转换为字符串
    if ($isStr) $content = implode('', $content);
    return $content;
}


function curl_file_get_contents3($array, $timeout = 10)
{
    $res = array();
    if (is_string($array)) $array = array($array);
    $mh = curl_multi_init(); //创建多个curl语柄
    $startime = getmicrotime();
    $ch = curl_init();
    foreach ($array as $k => $url) {
        $conn[$k] = curl_init($url);
        curl_setopt($conn[$k], CURLOPT_TIMEOUT, $timeout); //设置超时时间
        $user_agent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
        curl_setopt($conn[$k], CURLOPT_USERAGENT, $user_agent);
        curl_setopt($conn[$k], CURLOPT_MAXREDIRS, 7); //HTTp定向级别
        curl_setopt($conn[$k], CURLOPT_HEADER, 0); //这里不要header，加块效率
        curl_setopt($conn[$k], CURLOPT_FOLLOWLOCATION, 1); // 302 redirect
        curl_setopt($conn[$k], CURLOPT_RETURNTRANSFER, 1);
        @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        @curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
        curl_multi_add_handle($mh, $conn[$k]);
    }

    //防止死循环耗死cpu 这段是根据网上的写法
//        do {
//            $mrc = curl_multi_exec($mh,$active);//当无数据，active=true
//        } while ($mrc == CURLM_CALL_MULTI_PERFORM);//当正在接受数据时
//        while ($active and $mrc == CURLM_OK) {//当无数据时或请求暂停时，active=true
//            if (curl_multi_select($mh) != -1) {
//                do {
//                    $mrc = curl_multi_exec($mh, $active);
//                } while ($mrc == CURLM_CALL_MULTI_PERFORM);
//            }
//        }

    foreach ($array as $k => $url) {
        curl_error($conn[$k]);
        $res[$k] = curl_multi_getcontent($conn[$k]); //获得返回信息
        $header[$k] = curl_getinfo($conn[$k]); //返回头信息
        curl_close($conn[$k]); //关闭语柄
        curl_multi_remove_handle($mh, $conn[$k]); //释放资源
    }

    curl_multi_close($mh);
    $endtime = getmicrotime();
    $diff_time = $endtime - $startime;
    $return = array('diff_time' => $diff_time,
        'return' => $res,
        'header' => $header
    );
    return $return['return'][0];
}


function getmicrotime()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}

function swf_replace($nr, $thisurl, &$swfstr, $host = "")
{
    $arr = array();
    $nr = preg_replace("/<div\s+class=\"cornerlayger\">(.*)<\/div>/Uisx", "", trim($nr));
    $nr = preg_replace("/<p\s+class=\"imgtitle\">(.*)<\/p>/Uisx", "", $nr);
    $nr = preg_replace("/<div\s+class=\"cornerlayger\">(.*)<\/div>/Uisx", "", $nr);
    $nr = preg_replace("/点击图片进入下一页|点击图片进下页/Uisx", "", $nr);
    if ($host == "sina.com.cn") {
        if (preg_match_all("/<\!\-\-\s*flash\s+player\s+begin\s+\-\->.*<\!\-\-\s+flash\s+player\s+end\s+\-\-\>/Uisx", $nr, $nn)) {
            $swfstr = $nn[0][0];
            return $nr;
        }
        //$fn=fopen("d:/1.txt","w");fwrite($fn,$thisurl."\r\n".$nr);fclose($fn);
        if (preg_match_all("/<div[^<>]*id=\"artibody\"[^<>]*>.*<\!\-\-\spublish_helper_end\s\-\->.*<\/div>/Uisx", $nr, $nn)) {
            $swfstr = $nn[0][0];
            return $nr;
        }

        $temp = swfhost($nr, $thisurl, $swfstr, "sina.com.cn");
        if ($temp != "") $swfstr .= "[flv,500,400]" . $temp . "[/flv]\r\n";
    }


//echo $swfstr;exit;
    preg_match_all("/(<object[^<>]*>(.*<\/object>)?)/Uisx", $nr, $nn);
    for ($i = 0; $i < count($nn[1]); $i++) {
        if (preg_match("/\/ad\//i", $nn[1][$i])) continue;
        if (preg_match("/name=\"filename\"\s+value=\"([^<>]*\.(swf|flv|rm|rmvb|mov|avi|wmv|hlv)[^<>]*)\"/Uisx", $nn[1][$i], $ss)) {
            $mm = $ss;
        }

        if ($mm == "" && preg_match("/value=\"[^<>\s\"\']*(http:\/\/[^<>\s\"\']*\.(flv|rm|rmvb|mov|avi|wmv|hlv))[^<>]*\"/Uisx", $nn[1][$i], $ss)) {
            $mm = $ss;
        }

        if ($mm == "" && preg_match("/value=\"[^<>\s\"\']*(http:\/\/[^<>\s\"\']*\.(swf))[^<>]*\"/Uisx", $nn[1][$i], $ss)) {
            $mm = $ss;
        }

        if (in_array($mm[1], $arr)) continue;
        $arr[] = $mm[1];
        preg_match("/WIDTH\:\s*([0-9]+)px/Uisx", $nn[1][$i], $mm2);
        $width = $mm2[1];
        preg_match("/height\:\s*([0-9]+)px/Uisx", $nn[1][$i], $mm2);
        $height = $mm2[1];
        if ($width == "") {
            preg_match("/width=\"([0-9]+)\"/Uisx", $nn[1][$i], $mm2);
            $width = $mm2[1];
        }
        if ($height == "") {
            preg_match("/height=\"([0-9]+)\"/Uisx", $nn[1][$i], $mm2);
            $height = $mm2[1];
        }
        if (preg_match("/flashvars=\"(.*)\"/Uisx", $nn[1][$i], $mm3)) {
            $vars = (preg_match("/\?/", $mm[1]) ? "&" : "?") . $mm3[1];
        }
        if (!preg_match("/flv|swf|avi|rm|mp[0-9]|mov|wmv/i", $mm[1]) || (!preg_match("/\=/i", $mm[1] . $vars) && !preg_match("/[0-9]{3,}(?\.\/)/i", $mm[1] . $vars)) || preg_match("/\'|\"/i", $mm[1] . $vars)) continue;
        $flvurl = quanurl($mm[1], $thisurl) . $vars;
        if ($width < 1000 && $height > 300 && trim($flvurl) != "") {
            if (preg_match("/swf|flv/Uisx", "$mm[2]")) {
                $swfstr .= "[flash={$width},{$height}]" . $flvurl . "[/flash]\r\n";
                //$nr=str_replace($nn[0][$i],"[flash=x,{$width},{$height}]".quanurl($mm[1],$thisurl)."[/flash]\r\n",$nr);
            } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                $swfstr .= "[media={$width},{$height}]" . $flvurl . "[/media]\r\n";
                //$nr=str_replace($nn[0][$i],"[media=x,{$width},{$height}]".quanurl($mm[1],$thisurl)."[/media]\r\n",$nr);
            }
        }

    }


    if (preg_match_all("/vid=([^<>]*)(\&|\"|$|\>)/isx", $nr, $mm)) {
        $vid = $mm[1][0];
        if ($width == "") {
            preg_match("/width=\"([0-9]+)\"/Uisx", $nn[1][$i], $mm2);
            $width = $mm2[1];
        }
        if ($height == "") {
            preg_match("/height=\"([0-9]+)\"/Uisx", $nn[1][$i], $mm2);
            $height = $mm2[1];
        }

        if ($host == "ku6.com") {
            $mm[1] = "http://player.ku6.com/refer/{$vid}/v.swf";
            $mm[2] = "http://player.ku6.com/refer/{$vid}/v.swf";
        }

        $arr[] = $mm[1];
        //echo $nn[2];exit;
        if ($width <= 1000 && $height > 200 && trim($mm[2]) != "") {
            if (preg_match("/swf|flv/Uisx", "$mm[2]", $mmz)) {
                $swfstr .= "[flash={$width},{$height}]" . quanurl($mm[1], $thisurl) . "[/flash]\r\n";
            } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                $swfstr .= "[media={$width},{$height}]" . quanurl($mm[1], $thisurl) . "[/media]\r\n";
            }
        }
    }

    preg_match_all("/(<embed[^<>]*>(.*<\/embed>)?)/Uisx", $nr, $nn);
    for ($i = 0; $i < count($nn[1]); $i++) {
        if (preg_match("/\/ad\//i", $nn[1][$i]) || trim($nn[1][$i]) == "") continue;
        if (preg_match("/(?:file|src)=([^<>]*\.(swf|flv|rm|rmvb|mov|avi|wmv|hlv|mp[0-9]+)[^<>]*)\"/Uisx", $nn[1][$i], $mm)) {
            $mm[1] = urldecode(preg_replace("/\"/", "", $mm[1]));
            $mm[1] = preg_replace("/autostart=false/", "autostart=true", $mm[1]);
            $mm[1] = preg_replace("/&amp;/", "&", $mm[1]);

            if (in_array($mm[1], $arr)) continue;
            $arr[] = $mm[1];
            preg_match("/WIDTH=\"?\s*([0-9]+)/isx", $nn[1][$i], $mm2);
            $width = $mm2[1];
            preg_match("/height=\"?\s*([0-9]+)/isx", $nn[1][$i], $mm2);
            $height = $mm2[1];
            if (preg_match("/flashvars=\"(.*)\"/Uisx", $nn[1][$i], $mm3)) {
                $vars = (preg_match("/\?/", $mm[1]) ? "&" : "?") . $mm3[1];
            }
            if (!preg_match("/flv|swf|avi|rm|mp[0-9]|mov|wmv/i", $mm[1]) || preg_match("/\'|\"/i", $mm[1] . $vars)) continue;
            if (preg_match("/swf|flv/Uisx", "$mm[2]")) {
                $swfstr .= "[flash={$width},{$height}]" . quanurl($mm[1], $thisurl) . $vars . "[/flash]\r\n";
                //$nr=str_replace($nn[0][$i],"[flash=x,{$width},{$height}]".quanurl($mm[1],$thisurl)."[/flash]\r\n",$nr);
            } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                $swfstr .= "[media={$width},{$height}]" . quanurl($mm[1], $thisurl) . $vars . "[/media]\r\n";
                //$nr=str_replace($nn[0][$i],"[media=x,{$width},{$height}]".quanurl($mm[1],$thisurl)."[/media]\r\n",$nr);
            }
        }

    }

    preg_match_all("/\&lt\;object.*param\s+name=\&quot\;movie\&quot\;\s+value=\&quot\;([^<>]+)\&quot\;/Uisx", $nr, $nn);
    for ($i = 0; $i < count($nn[1]); $i++) {
        if (preg_match("/\/ad\//i", $nn[1][$i])) continue;
        preg_match("/WIDTH=(?:\"|\&quot\;)?\s*([0-9]+)/isx", $nn[$i][0], $mm2);
        $width = $mm2[1];
        preg_match("/height=(?:\"|\&quot\;)?\s*([0-9]+)/isx", $nn[$i][0], $mm2);
        $height = $mm2[1];
        if (!preg_match("/flv|swf|avi|rm|mp[0-9]|mov|wmv/i", $nn[1][$i]) || (!preg_match("/\=/i", $nn[1][$i] . $vars) && !preg_match("/[0-9]{3,}(?\.\/)/i", $nn[1][$i] . $vars)) || preg_match("/\'|\"/i", $nn[1][$i] . $vars)) continue;
        if ($width <= 1000 && $height > 200) {
            if (preg_match("/swf|flv/Uisx", "$nn[1][$i]", $oo)) {
                $swfstr .= "[flash={$width},{$height}]" . quanurl($nn[1][$i], $thisurl) . "[/flash]\r\n";
            } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                $swfstr .= "[media={$width},{$height}]" . quanurl($nn[1][$i], $thisurl) . "[/media]\r\n";
            }
        }
    }

    preg_match_all("/\,videoSrc\:\s+\'(.*)\'/Uisx", $nr, $nn);
    for ($i = 0; $i < count($nn[1]); $i++) {
        preg_match("/WIDTH=(?:\"|\&quot\;)?\s*([0-9]+)/isx", $nn[$i][0], $mm2);
        $width = $mm2[1];
        preg_match("/height=(?:\"|\&quot\;)?\s*([0-9]+)/isx", $nn[$i][0], $mm2);
        $height = $mm2[1];
        if (preg_match("/swf|flv/Uisx", "$nn[1][$i]", $oo)) {
            $swfstr .= "[flash=580,280]" . quanurl($nn[1][$i], $thisurl) . "[/flash]\r\n";
        } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
            $swfstr .= "[media=580,280]" . quanurl($nn[1][$i], $thisurl) . "[/media]\r\n";
        }
    }

    preg_match_all("/var\s*ad\s*=\s*'([^<>]*)';\s*var\s*w\s*=\s*'([0-9]*)';\s*var\s*h\s*=\s*'([0-9]*)';/Uisx", $nr, $nn);
    for ($i = 0; $i < count($nn[1]); $i++) {
        if (preg_match("/swf|flv/Uisx", "$nn[1][$i]", $oo)) {
            $swfstr .= "[flash={$nn[2][$i]},{$nn[3][$i]}]" . quanurl($nn[1][$i], $thisurl) . "[/flash]\r\n";
        } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
            $swfstr .= "[media={$nn[2][$i]},{$nn[3][$i]}]" . quanurl($nn[1][$i], $thisurl) . "[/media]\r\n";
        }
    }

    preg_match_all("/<script[^<>]*>(.*)<\/script>/Uisx", $nr, $nn);
    for ($i = 0; $i < count($nn[1]); $i++) {
        if (preg_match("/\/ad\//i", $nn[1][$i])) continue;
        if (preg_match("/\"file\"\s*\,\s*\"([^<>]*\.(swf|flv|rm|rmvb|mov|avi|wmv|hlv))\"/Uisx", $nn[1][$i], $ss)) {
            $mm = $ss;
        }
        if (preg_match("/file\s*\:\s*\"([^<>]*\.(swf|flv|rm|rmvb|mov|avi|wmv|hlv))\"/Uisx", $nn[1][$i], $ss)) {
            $mm = $ss;
        }
        if (preg_match("/data\s*=\s*([^<>]*\.(swf|flv|rm|rmvb|mov|avi|wmv|hlv))/Uisx", $nn[1][$i], $ss)) {
            $mm = $ss;
        }
        if (preg_match("/'src'\s*\,\s*'([^<>]*)'/Uisx", "$nn[1][$i]", $ss)) {
            $mm = $ss;
            $flash = 1;
        }

        if (in_array($mm[1], $arr)) continue;
        $arr[] = $mm[1];
        if (preg_match("/width\"?\s*(?:,|\:|\=)\s*\"?\s*([0-9]+)/isx", $nn[1][$i], $mm2)) $width = $mm2[1];
        if (preg_match("/height\"?\s*(?:,|\:|\=)\s*\"?\s*([0-9]+)/isx", $nn[1][$i], $mm2)) $height = $mm2[1];
        if (preg_match("/width=\"([0-9]+)\"/Uisx", $nn[1][$i], $mm2)) $width = $mm2[1];
        if (preg_match("/height=\"([0-9]+)\"/Uisx", $nn[1][$i], $mm2)) $height = $mm2[1];
        if (preg_match("/'width'\,'([0-9]+)'\,'height'\,'([0-9]+)'/Uisx", $nn[1][$i], $mm2)) {
            $width = $mm2[1];
            $height = $mm2[2];
        }
        if (preg_match("/'width'\,'([0-9]+)'\,'height'\,'([0-9]+)'/Uisx", $nn[1][$i], $mm2)) {
            $width = $mm2[1];
            $height = $mm2[2];
        }


        $flvurl = quanurl($mm[1], $thisurl);
        if ($width <= 1000 && $height > 200 && $flvurl != "" && !preg_match("/\"/", $flvurl)) {
            if (preg_match("/swf|flv/Uisx", "$mm[2]") || $flash) {
                $swfstr .= "[flash={$width},{$height}]" . $flvurl . "[/flash]\r\n";
                //$nr=str_replace($nn[0][$i],"[flash=x,{$width},{$height}]".quanurl($mm[1],$thisurl)."[/flash]\r\n",$nr);
            } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                $swfstr .= "[media={$width},{$height}]" . $flvurl . "[/media]\r\n";
                //$nr=str_replace($nn[0][$i],"[media=x,{$width},{$height}]".quanurl($mm[1],$thisurl)."[/media]\r\n",$nr);
            }
        }
    }

    if ($vid == "" && preg_match("/\/v\/[0-9]\/[a-z]\/([^<>]+)\.html/Uisx", $thisurl, $vv)) {
        $vid = $vv[1];
        if ($host == "qq.com") {
            $nn[1][0] = "http://static.video.qq.com/TPout.swf?vid={$vid}&auto=1";
            if (preg_match("/swf|flv/Uisx", $nn[1][$i], $oo)) {
                $swfstr .= "[flash=580,280]" . quanurl($nn[1][0], $thisurl) . "[/flash]\r\n";
            } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                $swfstr .= "[media=580,280]" . quanurl($nn[1][0], $thisurl) . "[/media]\r\n";
            }
        }
    }
    if ($vid == "" && preg_match("/\?vid=([^\&<>]+)/isx", $thisurl, $vv)) {
        $vid = $vv[1];
        if ($host == "qq.com") {
            $nn[1][0] = "http://static.video.qq.com/TPout.swf?vid={$vid}&auto=1";
            if (preg_match("/swf|flv/Uisx", $nn[1][$i], $oo)) {
                $swfstr .= "[flash=580,280]" . quanurl($nn[1][0], $thisurl) . "[/flash]\r\n";
            } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                $swfstr .= "[media=580,280]" . quanurl($nn[1][0], $thisurl) . "[/media]\r\n";
            }
        }
    }

    if (preg_match_all("/(mms\:\/\/.*\.(?:wmv|asf))/Uisx", $nr, $nn)) {
        $swfstr .= "[flash]" . $nn[1][0] . "[/flash]\r\n";
    }

    $swfstr = preg_replace("/vid\=\&/Uisx", "vid={$vid}&", $swfstr);
    $swfstr = preg_replace("/vid=\'\s*vid\s*\'/Uisx", "vid={$vid}", $swfstr);
    $swfstr = preg_replace("/http\:\/\/[^<>\s]+(http\:\/\/[^<>]+\.(?:swf|flv|mp[0-9]+|rm|rem|mov|avi|mpg|mpeg))/Uisx", "\\1", $swfstr);
    return $nr;
}

function changeloadimg($textarea, $rs, $thisurl = "", $notclfdl = 0)
{
    if ($rs['loadimg'] && !$notclfdl) {
        $GLOBALS['r'] = ($rs['refresh']) ? "&r=" . urlencode($thisurl) : "";
        $GLOBALS['c'] = ($rs['c']) ? "&c=1" : "";
        if (!function_exists('cbfun3')) {
            function cbfun3($nn)
            {
                return "[img]http://collect.longsunhd.com/source/plugin/yzs1013_pldr/getimg.php?url=" . surlencode($nn[1]) . $GLOBALS['r'] . $GLOBALS['c'] . "[/img]";
            }
        }
        $textarea = preg_replace_callback("/\[img\](?!http\:\/\/collect\.longsunhd\.com)(.*)\[\/img\]/Uisx", "cbfun3", $textarea);
    }
    unset($GLOBALS['r']);
    unset($GLOBALS['c']);
    return $textarea;
}

function curl3($post, $cookie = "")
{
    $POSTFIELDS = "";

    if (substr($post, 0, 7) == "http://") {
        $post = urltopoststr2($post, $cookie);
    }

    preg_match_all("/^Host\:(\s*.*)$/Uimx", $post, $nn);
    $host = trim(chop($nn[1][0]));
    $site = "http://" . $host;
    preg_match_all("/^(POST|GET)\s+(.*)\s+HTTP/Umx", $post, $uu);
    $url = preg_replace("/\/+$/", "", $site) . "/" . preg_replace("/^\/+/", "", chop($uu[2][0]));
    preg_match_all("/^Referer\:(\s*.*)$/Uimx", $post, $nn);
    $Referer = trim(chop($nn[1][0]));
    preg_match_all("/(?:\r\n\r\n|\n\n)(.*)$/Uis", $post, $nn);
    $Querystring = trim(chop($nn[1][0]));
    preg_match_all("/boundary=(.*)$/Uim", $post, $nn);
    $boundary = trim(chop($nn[1][0]));
    $filename = $url;
    //$filename=$url.(preg_match("/\?/",$url)?"&":"?").$Querystring;
    //$filename=preg_replace("/http\:\/\/[^\/]*\//Uisx","/",$filename);
    $user_agent = "Mozilla/99.99 (compatible; MSIE 99.99; Windows XP 99.99)";
    $POSTFIELDS = $Querystring;

    $ch = curl_init();


    $timeout = 60;
    curl_setopt($ch, CURLOPT_URL, $filename);
    //curl_setopt ($ch, CURLOPT_MUTE, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/99.99 (compatible; MSIE 99.99; Windows XP 99.99)");
    curl_setopt($ch, CURLOPT_HEADER, 1); //要求输出头信息
    if ($uu[1][0] == "POST") curl_setopt($ch, CURLOPT_POST, 1);
    if (preg_match("/multipart/Uisx", $post)) {
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=$boundary"));
        //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    }
    if ($Referer != "") curl_setopt($ch, CURLOPT_REFERER, $Referer);
    if ($cookie != "") curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    if ($Querystring != "" && $uu[1][0] == "POST") {
        curl_setopt($ch, CURLOPT_POSTFIELDS, $Querystring);
    }
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $result = curl_exec($ch);
    curl_close($ch);

    preg_match("/(^.*)(?:\r\n\r\n|\n\n)(.*?)$/Uis", $result, $nn);
    $header = $nn[1];
    $body = $nn[2];

    if (@gzinflate(substr($body, 10))) {
        $body = @gzinflate(substr($body, 10));
    }


    //---------------解chunk编码

    if (strpos($result, 'chunk')) {
        $tmpfile = tempnam('../../tmp', 'webcache');
        $fp = fopen($tmpfile, 'w');
        fwrite($fp, $result);
        fclose($fp);
        ob_start();
        readgzfile($tmpfile);
        $result = ob_get_contents();
        ob_end_clean();
        unlink($tmpfile);
    }

    $result = $header . "\r\n\r\n" . $body;
    $nr = $result;
    //$nr=preg_replace("/<(\/?script[^>]*)>/Uisx","<!--\\1-->",$nr);
    return $nr;
}

function chunk($result)
{
    if (@gzinflate(substr($result, 10))) {
        $result = @gzinflate(substr($result, 10));
    }
    if (strpos($result, 'chunk')) {
        $tmpfile = tempnam('/tmp', 'webcache');
        $fp = fopen($tmpfile, 'w');
        fwrite($fp, $result);
        fclose($fp);
        ob_start();
        readgzfile($tmpfile);
        $result = ob_get_contents();
        ob_end_clean();
        unlink($tmpfile);
    }
    return $result;
}

function curl4($post, $cookie = "")
{
    $POSTFIELDS = "";

    preg_match_all("/^Host\:(\s*.*)$/Uimx", $post, $nn);
    $host = trim(chop($nn[1][0]));
    $site = "http://" . $host;
    preg_match_all("/^(POST|GET)\s+(.*)\s+HTTP/Umx", $post, $uu);
    $url = preg_replace("/\/+$/", "", $site) . "/" . preg_replace("/^\/+/", "", chop($uu[2][0]));
    preg_match_all("/^Referer\:(\s*.*)$/Uimx", $post, $nn);
    $Referer = trim(chop($nn[1][0]));
    preg_match_all("/\r\n\r\n(.*)$/Uis", $post, $nn);
    $Querystring = trim(chop($nn[1][0]));
    preg_match_all("/boundary=(.*)$/Uim", $post, $nn);
    $boundary = trim(chop($nn[1][0]));
    $filename = $url;
    //$filename=$url.(preg_match("/\?/",$url)?"&":"?").$Querystring;
    $user_agent = "Mozilla/99.99 (compatible; MSIE 99.99; Windows XP 99.99)";
    $POSTFIELDS = $Querystring;

    $ch = curl_init();

    $timeout = 60;
    curl_setopt($ch, CURLOPT_URL, $filename);
    //curl_setopt ($ch, CURLOPT_MUTE, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/99.99 (compatible; MSIE 99.99; Windows XP 99.99)");
    curl_setopt($ch, CURLOPT_HEADER, 0); //要求输出头信息
    if ($uu[1][0] == "POST") curl_setopt($ch, CURLOPT_POST, 1);
    if (preg_match("/multipart/Uisx", $post)) {
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=$boundary"));
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    }
    if ($Referer != "") curl_setopt($ch, CURLOPT_REFERER, $Referer);
    if ($cookie != "") curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    if ($Querystring != "" && $uu[1][0] == "POST") {
        curl_setopt($ch, CURLOPT_POSTFIELDS, $Querystring);
    }

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

    $result = @curl_exec($ch);
    curl_close($ch);

    preg_match_all("/(^.*)\r\n\r\n(.*?)$/Uis", $result, $nn);
    $header = $nn[1];
    $body = $nn[2];
    if (@gzinflate(substr($body, 10))) {
        $result = @gzinflate(substr($nn[2][0], 10));
    }
    //$result=$body;
    $nr = $result;
    //$cookie=getcookie($result);
    //setcookieto();
    //$nr=preg_replace("/<(\/?script[^>]*)>/Uisx","<!--\\1-->",$nr);
    return $nr;
}

if (!function_exists('urltopoststr2')) {
    function urltopoststr2($post, $cookies)
    {
        $publicpoststr = <<<TEXT
GET {surl} HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, * / *
Accept-Language: zh-CN
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; Foxy/1; QQDownload 702; GTB7.2; Foxy/1; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C)
Accept-Encoding: gzip, deflate
cookies:{cookies}
Proxy-Connection: Keep-Alive
Host: {host}


TEXT;
        preg_match_all("/(http\:\/\/([^\/]*?))(.*)$/Uimx", $post, $mm);
        $host = $mm[2][0];
        $surl = $mm[3][0];
        $publicpoststr = str_replace("{host}", $host, $publicpoststr);
        $publicpoststr = str_replace("{surl}", $surl, $publicpoststr);
        $publicpoststr = str_replace("{cookies}", $cookies, $publicpoststr);
        return trim($publicpoststr) . "\r\n\r\n";
    }
}

function evalpublic(&$textarea, $thisurl, $params = array(), $rs = array(), $thisbaseurl = "", $thissecexe = "", $lie_a = false)
{
    global $nn55, $addreturn;
    $nn221 = $nn44 = $nn11 = $nn111 = $nn99 = $nn91 = $nn92 = $nn12=$nn222 = array();
    extract($params);
    foreach ($params as $k => $v) {
        if (is_array($v)) {
            if (function_exists($k)) {
                $v = call_user_func($k, $v);
            }
        }
    }
    $returntextarea = $textarea;
    if(!empty($nn221)) {
        if (count($nn221[1]) > 0) {
            $returntextarea = "";
            $nn22 = $nn221;
        }
    }
    if (!empty($nn22) &&(count($nn22[1]) > 0 || count($nn22['url']) > 0)) {
        $tempstr = "";
        $nn22[1] = (!isset($nn22[1]) && $nn22['url'] != "") ? $nn22['url'] : $nn22[1];
        $nn22[2] = (!isset($nn22[2]) && $nn22['title'] != "") ? $nn22['title'] : $nn22[2];
        for ($i = 0; $i < count($nn22[1]); $i++) {
            $nn22[1][$i] = utf8encode($nn22[1][$i]);
            $nn22[2][$i] = utf8encode($nn22[2][$i]);
            if ($nn22['url'][$i] != "" || $nn22['title'][$i] != "") {
                $url = urldecode($nn22['url'][$i]);
                $href = urldecode($nn22['href'][$i]);
                $title = urldecode($nn22['title'][$i]);
                if (!preg_match("/^[0-9]+$/", $nn22['jj'][$i])) {
                    $title .= $nn22['jj'][$i];
                }
            } else {
                if (preg_match("/(^http[^<>\"\'\s]*(?:jpg|jpeg|gif|png|bmp)|\s*[a-zA-Z0-9\/\\\.\?\&\-_]+(?:jpg|jpeg|gif|png|bmp)\s*$)/Uisx", $nn22[1][$i], $nn)) {
                    $url = trim($nn22[1][$i]);
                    $title = $nn22[2][$i];
                } else {
                    preg_match_all("/(http[^<>\"\'\s]*(?:jpg|jpeg|gif|png|bmp)|\s*[a-zA-Z0-9\/\\\.\?\&\-_]+(?:jpg|jpeg|gif|png|bmp)[^\s\"\'\d]*?)/Uisx", $nn22[2][$i], $nn);
                    sort($nn[1]);
                    $url = $nn[1][0];
                    $title = preg_replace("/\s/", "", strip_tags($nn22[1][$i]));
                    if (strlen($title) < 8) {
                        $nn22[1][$i] = preg_replace("/(?:alt|title|caption)=\s*\"\"/Uisx", "", $nn22[1][$i]);
                        preg_match("/(?:alt|title|caption)=\s*\"(.*)\"/Uisx", $nn22[1][$i], $nn);
                        $title = preg_replace("/\s/", "", strip_tags($nn[1]));
                    }
                }
            }
            $url = str_replace('\/', "/", trim($url));
            $url = preg_replace("/_small\.jpg/Uisx", ".jpg", trim($url));
            $url = preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx", "", trim($url));
            if ($href != "") {
                $tempstr .= "<a href=\"$href\">" . trim(createimgubb($url, $title, $rs['loadimg'], $thisurl, $thisbaseurl)) . "</a>";
            } else {
                if (trim($nn22['fromurl'][$i]) != "") {
                    $title = "";
                }
                $tempstr .= createimgubb($url, $title, $rs['loadimg'], $thisurl, $thisbaseurl);
            }
            if (trim($nn22['fromurl'][$i]) != "") {
                $fromurl = utf8encode($nn22['fromurl'][$i]);
                $fromurl = str_replace("\\", "", $fromurl);
                $fromurl = preg_replace("/(?<!\:)\/{2}/", "/", $fromurl);
                $tempstr .= "\r\n[fromurl]" . $fromurl . "[/fromurl]";
            }
        }
        $tempstr = deletePublic($tempstr, $thisurl, 0, $thisbaseurl, $lie_a);
        $returntextarea = (maxlen($tempstr) > maxlen($textarea)) ? $tempstr : $tempstr . "\r\n&nbsp;&nbsp;\r\n" . $textarea;
        $a = 1;
    }

    //yzs ★★★抓取视频AAA
    if (!empty($nn44) &&count($nn44[1]) > 0) {
        $tempstr = "";
        $flvurls=array();
        for ($i = 0; $i < count($nn44[1]); $i++) {
            $nn44[1][$i] = urldecode(utf8encode($nn44[1][$i]));
            $nn44[2][$i] = urldecode(utf8encode($nn44[2][$i]));
            $nn44[3][$i] = urldecode(utf8encode($nn44[3][$i]));
            if ($addreturn['flvbaseurl'] != "") {
                $thisurl = (is_array($addreturn['flvbaseurl'])) ? $addreturn['flvbaseurl'][0] : $addreturn['flvbaseurl'];
            }

            for($j=1;$j<=3;$j++) {
                if (preg_match("/^((?:https?|\/\/|blob\:https?)[^<>\s]*\.(flv|mpg|swf|avi|rm|mov|wmv|mp[0-9]+|m4v|f4v|swf|mxf|ts|mts|mkv|mpeg|asf|rmvb|3gp|vob|vod|divx|div|xvid|asx|asf|mpe|m1v|m2v|dat|dv))(?=\?|$)/Uisx", $nn44[$j][$i], $nn)) {
                    $nn44[$j][$i] = preg_replace("/blob\:/i", "", $nn44[$j][$i]);
                    $url = quanurl($nn44[$j][$i], $thisurl, $thisbaseurl);
                }elseif (preg_match("/^((?:https?|\/\/|blob\:https?)[^<>\s]*\.(jpg|png|jpeg|gif|bmp))/Uisx", $nn44[$j][$i], $nn)) {
                    $nn44[$j][$i] = preg_replace("/blob\:/i", "", $nn44[$j][$i]);
                    $aviimage = quanurl($nn44[$j][$i], $thisurl, $thisbaseurl);
                }elseif (preg_match("/^(?!:https?|\/\/|blob\:https?).+$/Uisx", $nn44[$j][$i], $nn)) {
                    $title=$nn44[$j][$i];
                }
            }
            if($url!=""&&!in_array($url,$flvurls)){
                $GLOBALS['flv']['url']=quanurl($url, $thisurl, $thisbaseurl);
                $GLOBALS['flv']['aviimage']=$aviimage;
                $GLOBALS['flv']['title']=$title;
            }

            $zz=($title!="")?"&title=".$title:"";
            $zz.=($aviimage!="")?"&aviimage=".$aviimage:"";
            $zz.=($title!="")?"&title=".$title:"";
            $hz = ((!preg_match("/\?/", $url))? "?" : "&").preg_replace("/^&/","",$zz);
            $hz=($hz=="?")?"":$hz;
            if (preg_match("/swf|flv|mp[0-9]+/i", $url)&&!in_array($url,$flvurls)) {
                $tempstr .= "[flash]" . quanurl($url, $thisurl, $thisbaseurl) . $hz . "[/flash]\r\n" . $title . "\r\n";
                $flvurls[]=$url;
            }
        }

        $tempstr = deletePublic($tempstr, $thisurl, 0);
        $returntextarea = (maxlen($tempstr) > maxlen($textarea)) ? $tempstr : $tempstr . "\r\n" . $textarea;
        $a = 1;
    }


    if (!empty($nn55) &&count($nn55[1]) > 0) {
        $tempstr = "";
        $inarr = array();
        $newnn55 = array();
        foreach ($nn55 as $k => $v) {
            if (!is_int($k)) {
                $newnn55[0][ifhypy($k)] = $v;
            }
        }
        for ($i = 0; $i < count($nn55[1]); $i++) {
            if ($nn55['name'][$i] != "") {
                $name = $nn55['name'][$i];
                $value = $nn55['value'][$i];
            } else {
                if (is_array($nn55[2][$i]) && count($nn55[2][$i]) > 0) {
                    $name = $nn55[1][$i];
                    $value = $nn55[2][$i];
                } else {
                    if (preg_match("/\:|：|<(?:B|strong)>/Uisx", $nn22[2][$i], $nn)) {
                        $name = $nn55[2][$i];
                        $value = $nn55[1][$i];
                    } else {
                        $name = $nn55[1][$i];
                        $value = $nn55[2][$i];
                    }
                    $name = utf8encode($name);
                    $value = utf8encode($value);
                }
            }
            $name = clzdname($name);
            $ywname = ifhypy(clzdname($name));
            if (in_array($name, $inarr)) {
                continue;
            } else {
                $inarr[] = $ywname;
            }
            $value = clzdvalue($value);
            if ($value != "" && $name != "") {
                $tempstr .= "\r\n[b]【" . $name . "】[/b]:" . $value;
            }
            $newnn55[0][$ywname] = $value;
        }
        $GLOBALS['nn55'] = $newnn55;
        $tempstr = deletePublic($tempstr, $thisurl, 0);
        $returntextarea = $tempstr . "\r\n" . $textarea;
        $a = 1;
    }

    //$nn11是前连html
    if (!empty($nn11) &&count($nn11[1]) > 0) {
        for ($i = 0; $i < count($nn11[1]); $i++) {
            $nr = $nn11[1][$i];
            $nr = preg_replace("/_small\.jpg/Uisx", ".jpg", $nr);
            $nr = preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx", "", $nr);
            if (trim($nr) != "") {
                if (preg_match("/\.(jpg|png|gif|jpeg)\s*(?<!html|htm)$/i", $nr)) {
                    $returntextarea = "\r\n" . trim(createimgubb($nr, $title, $rs['loadimg'], $thisurl, $thisbaseurl)) . "\r\n" . $returntextarea;
                } else {
                    $returntextarea = deletePublic($nr, $thisurl, 0) . "\r\n" . $returntextarea;
                }
            }
        }
    }

    if (!empty($nn12) &&count($nn12[1]) > 0) {
        for ($i = 0; $i < count($nn12[1]); $i++) {
            $nr = $nn12[1][$i];
            $nr = preg_replace("/_small\.jpg/Uisx", ".jpg", $nr);
            $nr = preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx", "", $nr);
            if (trim($nr) != "") {
                if (preg_match("/\.(jpg|png|gif|jpeg)\s*(?<!html|htm)$/i", $nr)) {
                    $returntextarea = $returntextarea . "\r\n" . trim(createimgubb($nr, $title, $rs['loadimg'], $thisurl, $thisbaseurl));
                } else {
                    $returntextarea = $returntextarea . "\r\n" . deletePublic($nr, $thisurl, 0);
                }
            }
        }
    }

    //$nn111是后连html,只采第一页的内容
    if (!empty($nn111) &&count($nn111) > 0&&$GLOBALS['page']=="") {
            for ($i = 0; $i < count($nn111); $i++) {
                $nr = $nn111[$i];
                $nr = preg_replace("/_small\.jpg/Uisx", ".jpg", $nr);
                $nr = preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx", "", $nr);
                if (trim($nr) != "") {
                    if (preg_match("/\.(jpg|png|gif|jpeg)\s*$/i", $nr)) {
                        $returntextarea.=trim(createimgubb($nr, $title, $rs['loadimg'], $thisurl, $thisbaseurl)) . "\r\n\r\n" . $nn222[$i] . "\r\n";
                    } else {
                        $returntextarea.=trim(createimgubb($nn222[$i], $title, $rs['loadimg'], $thisurl, $thisbaseurl)) . "\r\n" . clwz(strip_tags($nr)) . "\r\n\r\n";
                    }
                }
            }
    }

    //==nn99 是真正的内容地址
    if (!empty($nn99) &&count($nn99[1]) > 0) {
        $nn99[1][0] = preg_replace("/^\/\//", "https://", $nn99[1][0]);
        $thisurl=($GLOBALS['config']['nn99url'])?$GLOBALS['config']['nn99url']:$thisurl;
        $nr = redo(quanurl($nn99[1][0], $thisurl, $thisbaseurl), $thissecexe);
        fopenwtemp("nn99",$nr,quanurl($nn99[1][0], $thisurl, $thisbaseurl));
        if (is_string($nr)&&trim($nr)!="") $returntextarea = $nr;
        if (is_object($nr)) $returntextarea = $nr->textarea;
    }

    if (!empty($nn91) &&count($nn91[0]) > 0) {
        $nr = redo(quanurl($nn91[0], $thisurl, $thisbaseurl), $thissecexe);
        if (is_string($nr)&&trim($nr)!="") $returntextarea = $nr . $returntextarea;
        if (is_object($nr)) $returntextarea = $nr->textarea;
    }

    if (!empty($nn92) &&count($nn92[0]) > 0) {
        $nr = redo(quanurl($nn92[0], $thisurl, $thisbaseurl), $thissecexe);
        if (is_string($nr)&&trim($nr)!="") $returntextarea = $returntextarea . $nr;
        if (is_object($nr)) $returntextarea = $nr->textarea;
    }

    $textarea = $returntextarea;
    return $returntextarea;
}

//==img  ==climg ==处理图片函数
function createimgubb($url, $title, $loadimg, $thisurl, $thisbaseurl = "",$originstyle=0)
{
    $title2 = utf8encode($title);
    $textarea = "";

    if ($url != "") {
        $url = str_replace("\\", "", $url);
        $url = preg_replace("/(?<!\:|^)\/\//Uisx", "/", $url);
        if ($loadimg) {
            $url = str_replace("%", "BAIFENHAO", $url);
            if($originstyle){
                $textarea = "<img src=\"http://collect.longsunhd.com/source/plugin/yzs1013_pldr/getimg.php?url=" . surlencode(quanurl(trim($url), $thisurl, $thisbaseurl)) . "\"></img>\r\n";
            }else {
                $textarea = "[img]http://collect.longsunhd.com/source/plugin/yzs1013_pldr/getimg.php?url=" . surlencode(quanurl(trim($url), $thisurl, $thisbaseurl)) . "[/img]\r\n";
            }
        } else {
            $textarea = "[img]" . quanurl(trim($url), $thisurl, $thisbaseurl) . "[/img]\r\n";
        }
    }

    if (preg_match("/^https?\:\/\//Uisx", $title)) {
        $textarea = trim($textarea) . "\r\n[url={$title2}]" . $title2 . "[/url]\r\n";
    } else {
        $textarea = "\r\n{$textarea}\r\n{$title2}\r\n";
    }
    return $textarea;
}

function dore($re, $tempnr = "", $ytempnr = "", $thisurl = "", $rs = array())
{
    global $news;
    $textarea = "";
    $bug = 0;
    $nn22 = $nn221 = $nn11 = array();
    $cc = preg_split("/\|\|\||$/m", $re);
    for ($i = 0; $i < count($cc); $i++) {
        if (trim($cc[$i]) == "") continue;
        if (!preg_match("/\&\&\&/Uisx", $cc[$i])) {
            if (preg_match("/\:y(?=$|\:)/Uisx", trim($cc[$i]))) {
                $cc[$i] = preg_replace("/\:y(?=$|\:)/", "", $cc[$i]);
                $tempnr = $ytempnr;
            }
            if (preg_match("/\:nn([0-9]+)(?=$|\:)/Uisx", trim($cc[$i]), $mm4)) {
                $cc[$i] = preg_replace("/\:nn[0-9]+(?=$|\:)/Uisx", "", trim($cc[$i]));
                $cc[$i] = (!isutf8($cc[$i])) ? u(trim($cc[$i])) : trim($cc[$i]);
                preg_match_all("/" . trim($cc[$i]) . "/Uisx", $tempnr, ${"nn" . $mm4[1]});
            } else {
                if (trim($textarea) == "") {
                    $cc[$i] = (!isutf8($cc[$i])) ? u(trim($cc[$i])) : trim($cc[$i]);
                    preg_match_all("/" . trim($cc[$i]) . "/Uisx", $tempnr, $nn);
                    $textarea = trim($nn[1][0]);
                }
            }
        } else {
            $ddd = explode("&&&", $cc[$i]);
            $tempnr2 = $tempnr;
            if (count($ddd) > 1) {
                for ($d = 0; $d < count($ddd) - 1; $d++) {
                    preg_match_all("/" . trim($ddd[$d]) . "/Uisx", $tempnr2, $nn);
                    $tempnr2 = $nn[1][0];
                    //echo trim($ddd[$d]).$tempnr2;
                }

                if (preg_match("/\:nn([0-9]+)(?=\:|$)/Uisx", trim($ddd[count($ddd) - 1]), $mm4)) {
                    $ddd[count($ddd) - 1] = preg_replace("/\:nn[0-9]+(?=\:|$)/Uisx", "", trim($ddd[count($ddd) - 1]));
                    preg_match_all("/" . trim($ddd[count($ddd) - 1]) . "/Uisx", $tempnr, ${"nn" . $mm4[1]});
                }
            }
        }

    }

    if ($mm4[1] != null) {
        $oo = ${"nn" . $mm4[1]};
        if (count($oo) > 0) {
            $params = array("nn22" => $nn22, "nn221" => $nn221, "nn11" => $nn11);
            $textarea .= evalpublic($textarea, $thisurl, $params, $rs, $bug);
        }
    }
    return trim($textarea);
}

function surlencode($url)
{
    if (preg_match("/http%3A%2F%2F/Uisx", $url)) {
        return $url;
    }
    $url = urlencode(str_replace("%", "BAIFENHAO", $url));
    return $url;
}

function replacedxkh($nr)
{
    $nr = str_replace("<", "&lt;", $nr);
    $nr = str_replace(">", "&gt;", $nr);
    return $nr;
}

function loopbz($nr, $divre = "<div[^<>]*class=\"spaceborder\"[^<>]*>", $firstre = "<img[^<>]*src=\"([^<>]*(uface|userface)[^<>]*)\"[^<>]*>", $contentre = "<div\s+class=\"bshare\-image2share\"[^<>]*>(.*)<span")
{
    $first = $textarea = "";
    preg_match_all("/($divre)(.*)(?=$divre)/Uisx", $nr, $nn);
    for ($i = 0; $i < count($nn[1]); $i++) {
        if (preg_match("/$firstre/Uisx", $nn[0][$i], $mm) && $first == "") {
            //echo 4;
            $first = $mm[0];
            if ($contentre != "") {
                preg_match("/$contentre/Uisx", $nn[0][$i], $mm2);
                $textarea .= $mm2[1];
            } else {
                $textarea .= $nn[0][$i];
            }
        } elseif ($first != "" && preg_match("/" . addsla($first) . "/Uisx", $nn[0][$i])) {
            echo 5;
            if ($contentre != "") {
                preg_match("/$contentre/Uisx", $nn[0][$i], $mm2);
                $textarea .= $mm2[1];
            } else {
                $textarea .= $nn[0][$i];
            }
        }

    }
    return $textarea;
}


function utf8_unicode2($str)
{
    $temp = "";
    preg_match_all("/[\x80-\xff]?./", $str, $ar);
    foreach ($ar[0] as $v)
        //$temp.="&#".utf8_unicode($v).";";
        //$temp.="&amp;#".utf8_unicode(iconv("GB2312","UTF-8",$v)).";";
        $temp .= "&#" . utf8_unicode($v) . ";";
    return $temp;
}


function jsstart($name = 'default')
{
    global $ss_timing_start_times;
    $ss_timing_start_times[$name] = explode(" ", microtime());
}

function jsstop($name = 'default')
{
    global $ss_timing_stop_times;
    $ss_timing_stop_times[$name] = explode(" ", microtime());
}

function js($name = 'default')
{
    global $ss_timing_start_times, $ss_timing_stop_times;
    if (!isset($ss_timing_start_times[$name])) {
        return 0;
    }
    if (!isset($ss_timing_stop_times[$name])) {
        $stop_time = explode(" ", microtime());
    } else {
        $stop_time = $ss_timing_stop_times[$name];
    }
    $current = $stop_time[1] - $ss_timing_start_times[$name][1];
    $current += $stop_time[0] - $ss_timing_start_times[$name][0];
    return $current;
}


function swfhost($nr, $thisurl, &$swfstr, $host)
{
    switch ($host) {
        case "sina.com.cn":
            if (preg_match("/vid\s*=\"([0-9]+)\"/isx", $nr, $nn)) {
                $vid = $nn[1];
            }
            if (preg_match("/vid\s*\:\'([0-9]+)\'\,/Uisx", $nr, $nn)) {
                $vid = $nn[1];
            }
            if (preg_match("/uid\s*\:\'([0-9]+)\'\,/Uisx", $nr, $nn)) {
                $uid = $nn[1];
            }
            if (preg_match("/sid\s*\:\'([0-9]+)\'\,/Uisx", $nr, $nn)) {
                $sid = $nn[1];
            }
            if (preg_match("/tid\s*\:\'([0-9]+)\'\,/Uisx", $nr, $nn)) {
                $tid = $nn[1];
            }
            if (preg_match("/pid\s*\:\'([0-9]+)\'\,/Uisx", $nr, $nn)) {
                $pid = $nn[1];
            }
            $uid = ($uid == "") ? 6 : $uid;
            $tid = ($tid == "") ? 2 : $tid;
            $pid = ($pid == "") ? 1 : $pid;
//echo "http://v.iask.com/v_play.php?vid={$vid}&uid={$uid}&pid={$pid}&tid={$tid}&referrer=&ran=0.2793316".rand(1000,9999)."28716&r=video.sina.com.cn";
            $nr = curl_file_get_contents("http://v.iask.com/v_play.php?vid={$vid}&uid={$uid}&pid={$pid}&tid={$tid}&referrer=&ran=0.2793316" . rand(1000, 9999) . "28716&r=video.sina.com.cn");
            if (preg_match("/<url><\!\[CDATA\[(.*)\]\]><\/url>/Uisx", $nr, $nn)) {
                $url = $nn[1];
            }
            return $url;
            break;
    }
}

function unicode_decode($name)
{
    $name = trim($name);
    $name = preg_replace("/[\\\\\\|\/|\%]?u([0-9a-zA-Z]{4})/ie", 'zh2("\\1")', $name); //%u\\1
    $name = preg_replace("/(\\\u([0-9a-z]{1,4}))/ie", 'zh("\\1")', $name);
    $name = unicode_decode2($name);
    return $name;
}

function unicode_decode_utf8($name)
{
    $name = unicode_decode(trim($name));
    $name = mb_convert_encoding($name, "gb2312", "UTF-8");
    return $name;
}

//unitcode转gb2312
function unicode_decode0($name)
{
    $name = trim($name);
    $name = preg_replace("/[\\\\\\|\/|\%]?u([0-9a-zA-Z]{4})/ie", 'zh2("\\1")', $name); //%u\\1
    return $name;
}

function unicode_decode1($name)
{
    $name = trim($name);
    $name = preg_replace("/[\\\\\\|\/]?u([0-9a-zA-Z]{4})/ie", 'zh2("\\1")', $name); //%u\\1
    $name = preg_replace("/(\\\u([0-9a-z]{1,4}))/ie", 'zh("\\1")', $name);
    $name = unicode_decode2($name);
    return $name;
}


function zh($str)
{
    $code = base_convert(substr($str, 2, 2), 16, 10);
    $code2 = base_convert(substr($str, 4), 16, 10);
    $c = chr($code) . chr($code2);
    $c = iconv('UCS-2', 'GB2312//IGNORE', $c);
    return $c;
}

function zh2($str)
{
    $c = "&#x" . $str . ";";
    return $c;
}

//unitcode转gb2312
function unicode_decode2($str)
{
    $str = rawurldecode($str);
    preg_match_all("/(?:%u.{4})|&#x.{4};|&#\d+;|.+/U", $str, $r);
    $ar = $r[0];
    foreach ($ar as $k => $v) {
        if (substr($v, 0, 2) == '%u') {
            $ar[$k] = @iconv("UCS-2", "GB2312", pack("H4", substr($v, -4)));
        } elseif (substr($v, 0, 3) == "&#x") {
            $ar[$k] = @iconv("UCS-2", "GB2312", pack("H4", substr($v, 3, -1)));
        } elseif (substr($v, 0, 2) == "&#") {
            $ar[$k] = @iconv("UCS-2", "GB2312", pack("n", substr($v, 2, -1)));
        }
    }
    return join("", $ar);
}


//unitcode转utf8
function unicode_decode3($str)
{
    $str = rawurldecode($str);
    preg_match_all("/(?:%u.{4})|&#x.{4};|&#\d+;|.+/U", $str, $r);
    $ar = $r[0];
    foreach ($ar as $k => $v) {
        if (substr($v, 0, 2) == '%u') {
            $ar[$k] = @iconv("UCS-2", "utf-8", pack("H4", substr($v, -4)));
        } elseif (substr($v, 0, 3) == "&#x") {
            $ar[$k] = @iconv("UCS-2", "utf-8", pack("H4", substr($v, 3, -1)));
        } elseif (substr($v, 0, 2) == "&#") {
            $ar[$k] = @iconv("UCS-2", "utf-8", pack("n", substr($v, 2, -1)));
        }
    }
    return join("", $ar);
}


function isint($str)
{
    return preg_match("/^[0-9]+$/", $str);
}

function r($nr, $charset = 0)
{
    if (is_array($nr) || is_object($nr)) {
        $fn = fopen("d:/TMPTMP_ytempnr.htm", "w");
        $nr = ($charset) ? g($nr) : $nr;
        fwrite($fn, print_r($nr, 1));
        fclose($fn);
    } else {
        $nr = ($charset) ? g($nr) : $nr;
        $fn = fopen("d:/TMPTMP_ytempnr.htm", "w");
        fwrite($fn, $nr);
        fclose($fn);
    }
}

function ra($nr, $charset = 0)
{
    if (is_array($nr) || is_object($nr)) {
        $fn = fopen("d:/TMPTMP_ytempnr.htm", "a");
        $nr = ($charset) ? g($nr) : $nr;
        fwrite($fn, print_r($nr, 1));
        fclose($fn);
    } else {
        $nr = ($charset) ? g($nr) : $nr;
        $fn = fopen("d:/TMPTMP_ytempnr.htm", "a");
        fwrite($fn, $nr);
        fclose($fn);
    }
}

function r2($nr, $charset = 0)
{
    static $pretime;
    if ($pretime == "") {
        $fn = fopen("d:/TMPTMP_ytempnr.htm", "w");
        $nr = ($charset) ? g($nr) : $nr;
        fwrite($fn, "开始\r\n");
        fclose($fn);
    }
    if (is_array($nr) || is_object($nr)) {
        $fn = fopen("d:/TMPTMP_ytempnr.htm", "a+");
        $nr = ($charset) ? g($nr) : $nr;
        fwrite($fn, print_r($nr, 1) . "================执行时间:" . date("Y-m-d H:i:s") . "距上次:" . (time() - $pretime) . "秒\r\n");
        fclose($fn);
    } else {
        $nr = ($charset) ? g($nr) : $nr;
        $fn = fopen("d:/TMPTMP_ytempnr.htm", "a+");
        fwrite($fn, $nr . "================执行时间:" . date("Y-m-d H:i:s") . "距上次:" . (time() - $pretime) . "秒\r\n");
        fclose($fn);
    }
    $pretime = time();
}

function maxlen($arr)
{
    $temp = "";
    $arr = ($arr == null) ? "" : $arr;
    if (is_array($arr)) {
        for ($i = 0; $i < count($arr); $i++) {
            if (strlen(strim($arr[$i])) > strlen(strim($temp))) {
                $temp = strim($arr[$i]);
            }
        }
    } elseif (is_string($arr)) {
        if (strlen(strim($arr)) > strlen(strim($temp))) {
            $temp = strim($arr);
        }
    }
    return strlen($temp);
}

function strim($str)
{
    $str = preg_replace("/\s|　/", "", preg_replace("/<\/?(?!img|br)[^<>]*>/Uisx", "", $str));//|\[img\][^\[\]]*\[\/img\]
    return $str;
}

function getNextPage($rearr, $nr)
{
    //yzs 计算获取下一页的地址
    if (is_array($rearr) && count($rearr) > 0) {
        for ($pp = 0; $pp < count($rearr); $pp++) {
            if (!preg_match("/\&\&\&/Uisx", $rearr[$pp])) {
                $rearr[$pp] = preg_replace("/\:nn[0-9]+?(.*)$/Uisx", "", $rearr[$pp]);
                if (preg_match("/" . $rearr[$pp] . "/Uisx", $nr, $mm)) {
                    if (function_exists('nn88')) {
                        $mm[1] = nn88($mm[1]);
                    }
                    $mm[1] = str_replace('&amp;', '&', $mm[1]);
                    $return = $mm[1];
                    break;
                }
            } else {
                $ddd = explode("&&&", $rearr[$pp]);
                for ($d = 0; $d < count($ddd) - 1; $d++) {
                    preg_match_all("/" . trim($ddd[$d]) . "/Uisx", $nr, $nn);
                    $nn[1][0] = ($nn['nr'][0]) ? $nn['nr'][0] : $nn[1][0];
                    if (trim($nn[1][0]) == "") {
                        $tempnr = "";
                        break;
                    } else {
                        $tempnr = ($nn['value'][0]) ? $nn['value'][0] : $nn[1][0];
                        for ($j = 0; $j < count($nn[1]); $j++) {
                            $tempnrarr[] = $nn[1][$j];
                        }
                    }
                }
                if ($tempnr == "") continue;
                //带有&&&和:nn的re
                if (preg_match("/\:nn([0-9]+?)(.*$)/Uisx", trim($ddd[count($ddd) - 1]), $mm3)) {
                    $cc_i = preg_replace("/\:nn[0-9]+?(.*)$/Uisx", "", trim($ddd[count($ddd) - 1]));
                    preg_match_all("/" . trim($cc_i) . "/Uisx", $nr, $nn);
                    $return = $nn[1][0];
                }
            }
        }
    }
    return $return;
}

function renrarray($re, $nr, $array)
{
    if (preg_match("/" . trim($re) . "/Uisx", $nr, $nn)) {
        for ($i = 0; $i < count($array); $i++) {
            $GLOBALS[$array[$i]] = $nn[$i + 1];
        }
    }
}

function preg_count($re, $nr, &$nn = array())
{
    preg_match_all("/(" . trim($re) . ")/Uisx", $nr, $nn);
    return count($nn[0]);
}

function is_zw($str)
{
    if ($str == ""||is_array(nodecode($str))) return false;
    preg_match_all("/(。|，|？|！|[^a-z0-9\.<\/>\/]){20,}|([a-zA-Z0-9\&\;\,\.]{2,}\s+){3,}/Uisxu", $str, $nnhz);
    preg_match_all("/(<img[^<>]*>|\[img\].*\[\/img\])/Uisx", $str, $imnn);
    $c = $imgcount = count($imnn[0]);
    for ($i = 0; $i < $imgcount; $i++) {
        if (preg_match("/(?:width|height)=[\"']?([0-9]+?)/Uisx", $imnn[0][$i], $wh)) {
            if (($wh[1] < 100) && $wh[1] != 0) {
                $c--;
            }
        } elseif (preg_match("/\/imagesXX\/|\.(gif|png)/Uisx", $imnn[0][$i], $wh) && !preg_match("/\/[0-9]+\//Uisx", $imnn[0][$i], $wh)) {
            $c--;
        }
    }
    $imnn2 = preg_match_all("/(。|？|\.)/", $str);
    preg_match_all("/(?:\[|\<)flash[^<>]*(?:>|\])/Uisx", $str, $swfnn);
    if (count($nnhz[0]) > 0 && $imnn2 >= 1 || $c || count($swfnn[0]) > 0 || preg_match("/\{BAO[0-9]/", $str)) {
        return true;
    }
    return false;
}

function array_merge2($arr1, $arr2)
{
    if (count($arr1) < count($arr2)) {
        $t = $arr1;
        $arr1 = $arr2;
        $arr2 = $t;
    }
    $newarr = $arr1;
    for ($i = 0; $i < count($arr1); $i++) {
        if (is_array($arr2[$i])) $newarr[$i] = array_merge($arr1[$i], $arr2[$i]);
    }
    return $newarr;
}



function pagebug($news, $re, $nexturl)
{
    r($news->url . "\r\n" . $re . "\r\nNextUrl:" . $nexturl . "\r\n\r\n" . $news->yuannr . g($news->yuannr));
}

/**
 * 将字符串转换成unicode编码
 *
 * @param string $input
 * @param string $input_charset
 * @return string
 */
function str_to_unicode($input, $input_charset = 'gbk')
{
    $input = iconv($input_charset, "gbk", $input);
    preg_match_all("/[\x80-\xff]?./", $input, $ar);
    $b = array_map('utf8_unicode_', $ar[0]);
    $outstr = join("", $b);
    return $outstr;
}

function utf8_unicode_($c, $input_charset = 'gbk')
{
    $c = iconv($input_charset, 'utf-8', $c);
    return utf8_unicode($c);
}

// utf8 -> unicode
function utf8_unicode($c)
{
    switch (strlen($c)) {
        case 1:
            return $c;
        case 2:
            $n = (ord($c[0]) & 0x3f) << 6;
            $n += ord($c[1]) & 0x3f;
            break;
        case 3:
            $n = (ord($c[0]) & 0x1f) << 12;
            $n += (ord($c[1]) & 0x3f) << 6;
            $n += ord($c[2]) & 0x3f;
            break;
        case 4:
            $n = (ord($c[0]) & 0x0f) << 18;
            $n += (ord($c[1]) & 0x3f) << 12;
            $n += (ord($c[2]) & 0x3f) << 6;
            $n += ord($c[3]) & 0x3f;
            break;
    }
    return "&#$n;";
}

/**
 * 将unicode字符转换成普通编码字符
 *
 * @param string $str
 * @param string $out_charset
 * @return string
 */
function str_from_unicode($str, $out_charset = 'gbk')
{
    $str = preg_replace_callback("|&#([0-9]{1,5});|", 'unicode2utf8_', $str);
    $str = iconv("UTF-8", $out_charset, $str);
    return $str;
}

function unicode2utf8_($c)
{
    return unicode2utf8($c[1]);
}

function unicode2utf8($c)
{
    $str = "";
    if ($c < 0x80) {
        $str .= $c;
    } else if ($c < 0x800) {
        $str .= chr(0xC0 | $c >> 6);
        $str .= chr(0x80 | $c & 0x3F);
    } else if ($c < 0x10000) {
        $str .= chr(0xE0 | $c >> 12);
        $str .= chr(0x80 | $c >> 6 & 0x3F);
        $str .= chr(0x80 | $c & 0x3F);
    } else if ($c < 0x200000) {
        $str .= chr(0xF0 | $c >> 18);
        $str .= chr(0x80 | $c >> 12 & 0x3F);
        $str .= chr(0x80 | $c >> 6 & 0x3F);
        $str .= chr(0x80 | $c & 0x3F);
    }
    return $str;
}

/**
 * 模拟JS里的unescape
 *
 * @param unknown_type $str
 * @return unknown
 */
function unescape($str)
{
    $str = rawurldecode($str);
    preg_match_all("/(?:(?:%u.{4})|.{4};|&#\d+;|.+/U", $str, $r);
    $ar = $r[0];
    #print_r($ar);
    foreach ($ar as $k => $v) {
        if (substr($v, 0, 2) == "%u")
            $ar[$k] = iconv("UCS-2", "GB2312", pack("H4", substr($v, -4)));
        elseif (substr($v, 0, 3) == "")
            $ar[$k] = iconv("UCS-2", "GB2312", pack("H4", substr($v, 3, -1)));
        elseif (substr($v, 0, 2) == "&#") {
            echo substr($v, 2, -1) . "
";
            $ar[$k] = iconv("UCS-2", "GB2312", pack("n", substr($v, 2, -1)));
        }
    }
    return join("", $ar);
}


function utf8encode($source)
{
    if(!preg_match("/\s/",$source)&&preg_match("/\%/",$source)&&preg_match("/&/",$source)&&preg_match("/\?/",$source)) {
        $source = urldecode($source);
    }
    $source=preg_replace_callback("/(?:href|src)\s*=\s*[\"\'][^\'\"\s]+/",function($em){
        $em[0]=str_replace("\\","/",$em[0]);
        return $em[0];
    },$source);
    if (is_string($source)) {
        if (!preg_match("/\\\u[a-z0-9]{4}|%u[a-z0-9]{4}|\&\#[a-z0-9]{4,5}/", $source)) {
            return $source;
        }
    }

    $utf8str = '';
    $source = preg_replace('/\\\u/', '%u', $source);
    $source = convert_entities($source);
    $entities = explode('&#', $source);
    $size = count($entities);

    for ($i = 0; $i < $size; $i++) {
        $foo = $entities[$i];
        $nonEntity = strstr($foo, ';');

        if ($nonEntity !== false) {
            $unicode = intval(substr($foo, 0, (strpos($foo, ';') + 1)));
            // determine how many chars are needed to reprsent this unicode char
            if ($unicode < 128) {
                $bar = chr($unicode);
            } else if ($unicode >= 128 and $unicode < 2048) {
                $binVal = str_pad(decbin($unicode), 11, '0', STR_PAD_LEFT);
                $binPart1 = substr($binVal, 0, 5);
                $binPart2 = substr($binVal, 5);

                $char1 = chr(192 + bindec($binPart1));
                $char2 = chr(128 + bindec($binPart2));
                $bar = $char1 . $char2;
            } else if ($unicode >= 2048 and $unicode < 65536) {
                $binVal = str_pad(decbin($unicode), 16, '0', STR_PAD_LEFT);
                $binPart1 = substr($binVal, 0, 4);
                $binPart2 = substr($binVal, 4, 6);
                $binPart3 = substr($binVal, 10);

                $char1 = chr(224 + bindec($binPart1));
                $char2 = chr(128 + bindec($binPart2));
                $char3 = chr(128 + bindec($binPart3));
                $bar = $char1 . $char2 . $char3;
            } else {
                $binVal = str_pad(decbin($unicode), 21, '0', STR_PAD_LEFT);
                $binPart1 = substr($binVal, 0, 3);
                $binPart2 = substr($binVal, 3, 6);
                $binPart3 = substr($binVal, 9, 6);
                $binPart4 = substr($binVal, 15);

                $char1 = chr(240 + bindec($binPart1));
                $char2 = chr(128 + bindec($binPart2));
                $char3 = chr(128 + bindec($binPart3));
                $char4 = chr(128 + bindec($binPart4));
                $bar = $char1 . $char2 . $char3 . $char4;
            }

            if (strlen($nonEntity) > 1) {
                $nonEntity = substr($nonEntity, 1); // chop the first char (';')
            } else {
                $nonEntity = '';
            }
            $utf8str .= $bar . $nonEntity;
        } else {
            $utf8str .= $foo;
        }
    }
    $utf8str = preg_replace("/(\\\\)+n/", "", $utf8str);
    if (preg_match("/http\:\\\\\/\\\\\//", $utf8str)) {
        //$utf8str = stripcslashes($utf8str);
    }
    return $source;
    //return $utf8str;
}

function convert_entities($str)
{
    $str = preg_replace_callback('|%u([a-f0-9]{4})|i',
        create_function(
            '$matches',
            'return \'&#\' . hexdec($matches[1]) . \';\';'
        ),
        $str
    );
    return $str;
}

function lu2utf8($source)
{
    return utf8encode($source);
}

function print_r2($arr)
{
    $newarr = array();
    foreach ($arr as $k => $v) {
        if (is_array($v)) {
            foreach ($v as $k2 => $v2) {
                $newarr[$k][$k2] = utf8encode($v2);
            }
        } elseif (is_string($v)) {
            $newarr[$k] = utf8encode($v);
        }
    }
    $return = print_r($newarr, 1);
    r($return);
    return $return;
}

function clwzarray($nn, $thisurl, $clhc)
{
    $newarr = array();
    foreach ($nn as $k => $v) {
        if (is_array($v)) {
            foreach ($v as $k2 => $v2) {
                $newarr[$k][$k2] = deletePublic(utf8encode($v2), $thisurl, $clhc);
            }
        } elseif (is_string($v)) {
            $newarr[$k] = deletePublic(utf8encode($v), $thisurl, $clhc);
        }
    }
    return $newarr;

}

function danweiarray($array)
{
    $newarr = array();
    foreach ($array as $k => $v) {
        $newarr[$k] = $v[0];
    }
    return $newarr;
}

function gaiSrc($str, $src)
{
    $str = preg_replace("/src=([\"\'])?([^\s\"\']+)(?=\\1|\s|\"|\'>)/isx", "src=\\1" . trim($src), $str);
    return $str;
}

function deletePublic($textarea, $thisurl, $clhc, $thisbaseurl = "", $lie_a = false, $keeptable = 0)
{
    if (is_string($textarea)) {
        $textarea = preg_replace("/<(img)[^<>]*display:none[^<>]*>/Uisx","",$textarea);
        $textarea = utf8encode($textarea);
        $textarea = strip_jscss($textarea, $lie_a); //#### todo 过滤函数
        $textarea = preg_replace("/<h([0-9]+)\b[^<>]*>(.*)<\/h\\1>/Uisx", "[b]\\2[/b]", $textarea);
        $textarea = preg_replace("/width\>/Uisx", "width&gt;", $textarea);
        $textarea = preg_replace("/\&emsp\;/Uisx", "&nbsp;", $textarea);
        $textarea = preg_replace("/(<img[^<>]*)\s+?\/>/Uisx", "\\1>", $textarea);
        $textarea = preg_replace("/<span[^<>]*style=\\\?\"display\:none\\\?\"[^<>]*>.*<\/span>/Uisx", "", trim($textarea));
        $textarea = preg_replace("/\(微博\)/m", "", trim($textarea));
        $textarea = preg_replace("/([0-9]+\-[0-9]+\-[0-9]+\s[0-9]+\:[0-9]+\:[0-9]+\s上传).*$/m", "", $textarea);
        if($_GET['ubb']) $textarea = preg_replace("/<(\/?)(b|strong)\s*\/?>/Uisx", "[\\1b]", $textarea);
        $textarea = preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx", "", $textarea);
        $textarea = preg_replace("/<\!\-\-enpproperty(?=\<)|(?<=\>)\/enpproperty\-\->|<\!\-\-\/?enpproperty\-\->/i", "", trim($textarea));
        $textarea = preg_replace("/([0-9\-]+\s+[0-9\:]+|[0-9]天前)\s*(上传|修改|发表|更新)/Uisx", "", trim($textarea));
        $textarea = preg_replace("/<fieldset[^<>]*>(.*)<\/fieldset>/Uisx", "", trim($textarea));
        $textarea = str_replace('src="static/image/common/none.gif" ', '', $textarea);
        $textarea = str_replace('zoomfile', 'src', $textarea);
        $textarea = preg_replace("/<\/?br\s*\/?>|&lt;\/br\s*\/?&gt;/Uisx", "\r\n", $textarea);
        $textarea = htmltotxt($textarea, $clhc, $thisurl, $thisbaseurl, $lie_a, $keeptable);
        $textarea = preg_replace("/\[img\][^<>\[\]]*(\/images?\/smiley|images?\/common\/|\/images?\/smilies\/|\/miba\/images\/|images\/attachicons\/|\/common\/cf\/)[^<>\[\]]*\[\/img\]|\[b\]下载\[\/b\]|\([0-9\.a-z\s]+KB\)|[0-9]+天前[0-9\:]+?|附件\:\s*您所在的用户组无法下载或查看附件|<\/?blockquote[^<>]*>/Uisx", "", $textarea);
        $textarea = preg_replace("/\([\s0-9\.]+KB\,?\s*(下载次数\:\s*[\s0-9]+)?\)|下载次数\:[\s0-9]+?|(\s|　)[^\s]+\.jpg(\s|　)/Uisx", "\r\n", $textarea);
        $textarea = preg_replace("/本帖.*[0-9\-\s\:]编辑|<\/img>|<br\s*\/>|\&lt\;br\s*\/\&gt\;/Uisx", "", $textarea);
        $textarea = preg_replace("/本主题由[^\r\n]*/isx", "", $textarea);
        $textarea = preg_replace("/保存到相册|点击文件名|马上注册，.*？注册|\[img\][^<>\[\]]*qq_login.gif\[\/img\]/Uisx", "", $textarea);
        $textarea = preg_replace("/　　回复.*$/Uisx", "", $textarea);
        //$textarea = preg_replace("/(\r(\s)*\n)+|[\r\n](\s|[\x{3000}])*[\r\n]+/u", "\n", $textarea);
        $textarea = preg_replace("/[\r\n]+　　(\[hr\]\s*)+/", "[hr]", $textarea);
        $textarea = preg_replace("/(?:\[hr\](　|\s)*)+/", "[hr]", $textarea);
        $textarea = preg_replace("/<\!\-\-(?!(?<!<\!\-\-).*\-\->)/", "", $textarea);
        $textarea = preg_replace("/<span[^<>]*>|<\/\s*span>/Uisx", "", $textarea);
    } else if (is_array($textarea)) {
        foreach ($textarea as $k => $v) {
            $textarea[$k] = deletePublic($v, $thisurl, $clhc);
        }
    }
    return $textarea;
}

function jiebao($tempnr)
{
    $tempnr = preg_replace("/<div[^<>]*>(?:\s*<div[^<>]*>)?(<\/?(a|span|p|br)[^<>]*>|\s|\&nbsp\;)*(<img[^<>]*>)(<" . "?\/?(a|span|p|br)[^<>]*>|([^\<\>a-z0-9_\s]|\&nbsp\;|\s))*<\/div>(\s*<\/div>)??/Uisx", "\\3\\4", $tempnr);
    return $tempnr;
}

function strlen_jifen($str)
{
    $str = preg_replace("/<a\s?[^<>]*>.*<\/a>/Uisx", "", $str);
    $str = preg_replace("/<[^<>]*>/Uisx", "", $str);
    $str = preg_replace("/\s+/isx", " ", $str);
    return strlen($str);
}

function hasimg($str)
{
    if (preg_match("/src=/", $str)) {
        return true;
    }
    return false;
}

function stripa($str)
{
    $str = preg_replace("/<a\s?[^<>]*>.*<\/a>/Uisx", "", $str);
    return $str;
}

function curl38($url, $cookie2 = "", $Referer = "", $Querystring = "", $proxy = "")
{
    static $urlold;
    $timeout = 2;
    //$url = str_replace("%", "%25", trim(chop($url)));
    //echo $url;exit;
    $GLOBALS['debugger']['curr'][count($GLOBALS['debugger']['curr'])-1]['zqff'][]="curl38";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    preg_match("/http:\/\/([^\/]+)/", $url, $nn);
    $host = $nn[1];
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0");
    //curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36");
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    if ($proxy != "") curl_setopt($ch, CURLOPT_PROXY, $proxy);//自己设置的代理，
//    curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'longsunhd:longsunhd8381');//公司上网的账号密码，
    if ($Referer != "") curl_setopt($ch, CURLOPT_REFERER, $Referer);
    if ($cookie2 != "") curl_setopt($ch, CURLOPT_COOKIE, $cookie2);
    if ($Querystring != "") curl_setopt($ch, CURLOPT_POST, 1);
    if ($Querystring != "") curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
    if ($Querystring != "") curl_setopt($ch, CURLOPT_POSTFIELDS, $Querystring);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        // 'Content-Type: application/json; charset=utf-8',
        // 'X-Requested-With: XMLHttpRequest',
        "Host: $host",
        'Content-Type: application/x-www-form-urlencoded',
        'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
        'Accept-Encoding: gzip, deflate',
        'Connection: Keep-Alive',
    ));
    ob_start();
    echo curl_exec($ch);
    //print_r(curl_getinfo($ch,CURLINFO_HEADER_OUT));
    curl_close($ch);
    $result = ob_get_contents();
    ob_end_clean();

    $cookie = getcookies($result, $cookie2);
    if ($url!=$urlold&&preg_match("/^Location:\s*([^\r\n]+)/imx", $result, $nn)) {
        $url = quanurl(trim($nn[1]), $url);
        $urlold=$url;
        $result = curl38($url, $cookie);
        return $result;
    }

    if (preg_match("/^.*(?:\r\n\r\n|\n\n)(.*?)$/Uis", $result, $nn)) {
        $body = $nn[1];
        if (preg_match("/^.*(?:Connection\:|Content-Type\:).*(?:\r\n\r\n|\n\n)(.*?)$/Uis", $body, $nn)) {
            $body = $nn[1];
        }
    }
//echo $body;exit;
    if (@gzinflate(substr($body, 10))) {
        $body = @gzinflate(substr($body, 10));
    }
    fopenwtemp("curl38",$body,$url);
    return $body;
}


function curl39($url, $cookie = "", $Referer = "", $Querystring = "")
{
    $timeout = 15;
    //$url = str_replace("%", "%25", trim(chop($url)));
    $GLOBALS['debugger']['curr'][count($GLOBALS['debugger']['curr'])-1]['zqff'][]="curl39";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    preg_match("/http:\/\/([^\/]+)/", $url, $nn);
    $host = $nn[1];
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0");
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    if ($Referer != "") curl_setopt($ch, CURLOPT_REFERER, $Referer);
    if ($cookie != "") curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    if ($Querystring != "") curl_setopt($ch, CURLOPT_POST, 1);
    if ($Querystring != "") curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
    if ($Querystring != "") curl_setopt($ch, CURLOPT_POSTFIELDS, $Querystring);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        // 'Content-Type: application/json; charset=utf-8',
        // 'X-Requested-With: XMLHttpRequest',
        "Host: $host",
        'Content-Type: application/x-www-form-urlencoded',
        'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
        'Accept-Encoding: gzip, deflate',
        'Connection: Keep-Alive',
        'Pragma: no-cache',

    ));

    ob_start();
    echo curl_exec($ch);
    curl_close($ch);
    $result = ob_get_contents();
    ob_end_clean();

    if (preg_match("/^Location:\s*([^\r\n]+)/imx", $result, $nn)) {
        $url = trim($nn[1]);
        $result = curl38($url);
    } else {
        if (preg_match("/^.*(?:\r\n\r\n|\n\n)(.*?)$/Uis", $result, $nn)) {
            $body = $nn[1];
            if (preg_match("/^.*(?:Connection\:|Content-Type\:).*(?:\r\n\r\n|\n\n)(.*?)$/Uis", $body, $nn)) {
                $body = $nn[1];
            }
        }
        if (@gzinflate(substr($body, 10))) {
            $body = @gzinflate(substr($body, 10));
        }
    }
    return $body;
}

function clquerystring($arr)
{
    $s = "";
    foreach ($arr as $k => $v) {
        $s .= "" . urlencode($v) . ",";
    }
    return substr($s, 0, -1);
}

function is_root($str)
{
    $str = trim($str);
    $c = preg_count("\/", $str);
    if ($str == "" || $str == "\\" || $c < 3 && substr($str, 0, 7) == "http://" || $c == 3 && substr($str, -1, 1) == "/" && substr($str, 0, 7) == "http://") {
        return true;
    }
    return false;
}

function paiban($str)
{
    $str = preg_replace("/　*?(([\(\)\[\]a-z]+?)|([\(\)\[\]0-9])+(?=\.|\:|、|\(\)))(\.|\:|、|\r|\n)?\s*　　/Uis", "　　\\1", $str);
    $str = preg_replace("/[\r\n]\s*(?!。|？|”|！|：)(?:\s|　)*([0-9]+)(?:\s|　)*/is", "\\1", $str);
    $str = preg_replace("/\s*　　(?=。|？|”|：|\[\/b\])|\[\/b\](?:\s|　)*\[b\]/is", "", $str);
    $str = preg_replace("/(\[\/b\]|\)|）|）|　)(?:\s|　)*((?:[0-9a-z]|\[b\]|一|二|三|四|五|六|七|八|九|十|http\:\/\/)+)/is", "\\1" . "\r\n\r\n" . "　　　\\2", $str);
    $str = preg_replace("/(?<!。|？|”|！)((\r?\n　*)+)*/is", "", $str);
    $str = preg_replace("/(?<=。|？|”|！)([0-9]+)/is", "\r\n　　\\1", $str);
    $str = preg_replace("/(\([0-9a-z]+\))(\s|　)*/is", "\r\n　　\\1", $str);
    $str = preg_replace("/(（[0-9a-z]+）)(\s|　)*/is", "\r\n　　\\1", $str);
    $str = preg_replace("/\[\/b\]　*/is", "[/b]\r\n　　", $str);
    $str = preg_replace("/(?:　|\s)*(、|\)|）|“|（|\(|\))(　|\s)*/is", "\\1", $str);
    $str = preg_replace("/(\(|（)(\s|　)*/is", "\\1", $str);
    $str = preg_replace("/(\[(?:\/img|\/flash|\/media)\])/is", "\\1\r\n", $str);
    $str = preg_replace("/(?<=\s|\W)([0-9]+\.)(?!\/|\.|[a-z])/is", "\r\n\\1", $str);
    return $str;
}

function is_re($re)
{
//    if(preg_match("/(?<!\\\)\(([^\(\)](?!(?<!\\\)\))|\([^\(\)]*\)*)*$/Uisx",$re)){
//        return false;
//    }
    return true;
}

function ddd2($nn, $title, $rs, $thisurl, $thisbaseurl)
{
    return createimgubb($nn[1], $title, $rs["loadimg"], $thisurl, $thisbaseurl);
}

function ttbb($nn)
{
    global $title, $rs, $thisurl, $thisbaseurl, $TTBB;
    $GLOBALS['title'] = $title;
    $GLOBALS['rs'] = $rs;
    $GLOBALS['thisurl'] = $thisurl;
    $GLOBALS['thisbaseurl'] = $thisbaseurl;
    $str = $TTBB[$nn[1][0]];
    $str = preg_replace("/<table[^<>]*>/Uisx", "[TABLE=50%,#E5EDF2]", $str);
    $str = preg_replace("/<\/table[^<>]*>/Uisx", "[/table]", $str);
    $str = preg_replace("/<tr[^<>]*>/Uisx", "[tr]", $str);
    $str = preg_replace("/<\/tr[^<>]*>/Uisx", "[/tr]", $str);
    $str = preg_replace("/<td[^<>]*>/Uisx", "[td]", $str);
    $str = preg_replace("/<\/td[^<>]*>/Uisx", "[/td]", $str);
    $str = preg_replace("/<th[^<>]*>/Uisx", "[td]", $str);
    $str = preg_replace("/<\/th[^<>]*>/Uisx", "[/td]", $str);
    $str = preg_replace("/<(?!img)[^<>]*>/Uisx", "", $str);
    if (!function_exists('cbfun4')) {
        function cbfun4($nn)
        {
            return createimgubb($nn[1], $GLOBALS['title'], $GLOBALS['rs']["loadimg"], $GLOBALS['thisurl'], $GLOBALS['thisbaseurl']);
        }
    }
    $str = preg_replace_callback("/<(?:img)[^<>]*src=\"(.*)\"(?:[^<>]|(?<=width)>)*?" . ">/Uisx", "cbfun4", $str);
    unset($GLOBALS['title']);
    unset($GLOBALS['rs']);
    unset($GLOBALS['thisurl']);
    unset($GLOBALS['thisbaseurl']);
    return $str;
}

function clzdname($str)
{
    $str = preg_replace("/\s|\:|：|\r|\n|　|\-/", "", strip_tags($str));
    $str = preg_replace("/[\\\!a-z_\s\{\}\-\.\$]+?[\\\!\{\}\.\$][\\\!a-z_\s\{\}\.\$\-]+?/U", "", $str);
    $str = preg_replace("/\!|\?|\&[a-z]+\;/", "", $str);
    return trim($str);
}

function clzdvalue($str)
{
    if (is_string($str)) {
        $str = preg_replace("/\:|：|\r|\n/", "", strip_tags(trim($str), "<IMG>"));
        $str = preg_replace("/\s+/", " ", $str);
    }
    return $str;
}

function array_merge3($oldarr, $arr, $aaname = "Array")
{
    $a = 1;
    if (!name_exists($arr)) {
//        for ($i = 0; $i < count($arr[1]); $i++) {
//            $oldarr[0][] = $arr[0][$i];
//            $oldarr[1][] = $arr[1][$i];
//            $oldarr[2][] = $arr[2][$i];
//        }
        $oldarr = $arr;
    } else {
        foreach ($arr as $k => $v) {
            if (is_int($k)) continue;
            if (is_array($v) && count($v) > 1) {
                $oldarr[0][] = "";
                $oldarr[1][] = trim($aaname);
                $oldarr[2][] = delnamearr($arr);
                break;
            } else {
                $oldarr[0][] = "";
                $oldarr[1][] = trim($k);
                $oldarr[2][] = trim($v[0]);
            }
        }
    }
    return $oldarr;
}


function array_merge4($oldarr, $arr, $aaname = "Array")
{
    $a = 1;
    if (!name_exists($arr)) {
        for ($i = 0; $i < count($arr[1]); $i++) {
            $oldarr[0][] = $arr[0][$i];
            $oldarr[1][] = $arr[1][$i];
            $oldarr[2][] = $arr[2][$i];
        }
    } else {
        foreach ($arr as $k => $v) {
            if (is_int($k)) continue;
            if (is_array($v) && count($v) > 1) {
                $oldarr[0][] = "";
                $oldarr[1][] = trim($k);
                $oldarr[2][] = join(",", array_unique($v));
                break;
            } else {
                $oldarr[0][] = "";
                $oldarr[1][] = trim($k);
                $oldarr[2][] = trim($v[0]);
            }
        }
    }
    return $oldarr;
}

function array_merge5($oldarr, $arr, $aaname = "Array")
{
    $a = 1;
    if (!name_exists($arr)) {
        for ($i = 0; $i < count($arr[1]); $i++) {
            $oldarr[0][] = $arr[0][$i];
            $oldarr[1][] = $arr[1][$i];
            $oldarr[2][] = $arr[2][$i];
            if(!empty($arr[3][$i])) $oldarr[3][] = $arr[3][$i];
            if(!empty($arr[4][$i]))$oldarr[4][] = $arr[4][$i];
            $oldarr['title'][] = $arr['title'][$i];
            $oldarr['url'][] = $arr['url'][$i];
            $oldarr['fromurl'][] = $arr['fromurl'][$i];
        }
    } else {
        foreach ($arr as $k => $v) {
            if (is_int($k)) continue;
            if (!isset($oldarr[$k])) {
                $oldarr[$k] = array();
            }
            if (is_array($v)) {
                $oldarr[$k] = array_merge($oldarr[$k], $v);
            } else {
                $oldarr[$k][] = $v;
            }
        }
    }
    return $oldarr;
}

function delarrayindex0($arr)
{
    $newarr = array();
    $newarr[0] = $arr[1];
    $newarr[1] = $arr[2];
    return $newarr;
}

function name_exists($arr)
{
    foreach ($arr as $k => $v) {
        if (preg_match("/^[^0-9]+$/", $k)) {
            if ($k != "name" && $k != "value") {
                return true;
                break;
            }
        }
    }
    return false;
}

function delnamearr($arr)
{
    $newarr = array();
    foreach ($arr as $k => $v) {
        if (preg_match("/^[^0-9]+$/", $k)) {
            for ($i = 0; $i < count($arr[$k]); $i++) {
                $newarr[$i][$k] = $v[$i];
            }
        }
    }
    return $newarr;
}

function base64_decode_array($arr)
{
    $newarr = array();
    foreach ($arr as $k => $v) {
        $newarr[$k] = base64_decode($v);
    }
    return $newarr;
}

function clnn66($nn66)
{
    for ($i = 0; $i < count($nn66[1]); $i++) {
        $arr[$nn66[1][$i]] = $nn66[2][$i];
    }
    return $arr;
}

function ifhypy($str)
{
    return hypy($str);
}

function getKeyName($arr)
{
    $newarr = array();
    if ($arr['key'] != "") {
        $newarr['$key'] = $arr['key'];
    } else {
        foreach ($arr as $k => $v) {
            if (!is_int($k)) $newarr[] = $k;
        }
        $newarr[$newarr['$key']] = $newarr[0];
    }
    return $newarr[$newarr['$key']];
}


function multiDownload($urlArray)
{
    if (empty($urlArray)) return false;
    $isStr = false;
    if (is_string($urlArray)) {
        $urlArray = array($urlArray);
        $isStr = true;
    }

    $mh = curl_multi_init();
    $curlArray = array();

    foreach ($urlArray as $i => $url) {
        $curlArray[$i] = curl_init($url);
        curl_setopt($curlArray[$i], CURLOPT_RETURNTRANSFER, true); //设置为true表示返回抓取的内容，而不是直接输出到浏览器上。TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly
        curl_setopt($curlArray[$i], CURLOPT_AUTOREFERER, true); //自动设置referer。TRUE to automatically set the Referer: field in requests where it follows a Location: redirect.
        curl_setopt($curlArray[$i], CURLOPT_FOLLOWLOCATION, true); //跟踪url的跳转，比如301, 302等
        curl_setopt($curlArray[$i], CURLOPT_MAXREDIRS, 2); //跟踪最大的跳转次数
        curl_setopt($curlArray[$i], CURLOPT_HEADER, 0); //TRUE to include the header in the output.
        curl_setopt($curlArray[$i], CURLOPT_ENCODING, ""); //接受的编码类型,The contents of the "Accept-Encoding: " header. This enables decoding of the response. Supported encodings are "identity", "deflate", and "gzip". If an empty string, "", is set, a header containing all supported encoding types is sent.
        curl_setopt($curlArray[$i], CURLOPT_CONNECTTIMEOUT, 5); //连接超时时间
        curl_setopt($curlArray[$i], CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0");
        curl_multi_add_handle($mh, $curlArray[$i]); //curl_multi_add_handle --  Add a normal cURL handle to a cURL multi handle
    }
    $running = NULL;
    $count = 0;
    do {
        //10秒钟没退出，就超时退出
        if ($count++ > 100) break;
        usleep(200000);
        curl_multi_exec($mh, $running); //curl_multi_exec --  Run the sub-connections of the current cURL handle
    } while ($running > 0);

    $content = array();

    foreach ($urlArray as $i => $url) {
        $content[$url] = curl_multi_getcontent($curlArray[$i]); //curl_multi_getcontent --  Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set
    }

    //curl_multi_remove_handle --  Remove a multi handle from a set of cURL handles
    foreach ($urlArray as $i => $url) {
        curl_multi_remove_handle($mh, $curlArray[$i]);
    }

    //curl_multi_close --  Close a set of cURL handles
    curl_multi_close($mh);
    //如果参数$urlArray是字符串，则将返回值也转换为字符串
    if ($isStr) $content = implode('', $content);
    return $content;
}

function getCookie2($nr)
{
    preg_match("/setCookie\:\s*([^<>]+)$/", $nr, $nn);
    return $nn[1];
}


function getCookies2($nr, $cookie)
{
    preg_match_all("/Set-Cookie\:\s+(.*)(?:$|(?:path|domain|expires)\s*=)/Uimx", $nr, $nn);
    $cstr = "$cookie";
    for ($i = 0; $i < count($nn[1]); $i++) {
        $cstr .= ";" . trim($nn[1][$i]);
    }

    preg_match_all("/document\.cookie=['\"]([^<>]*)['\"]/Uimx", $nr, $nn);
    for ($i = 0; $i < count($nn[1]); $i++) {
        $cstr .= ";" . trim($nn[1][$i]);
    }


    $str = preg_replace("/\;+/", ";", $cstr);
    $str = preg_replace("/^\;/", "", $str);
    $nn = explode(";", $str);
    $arr = array();
    $arr2 = array();
    foreach ($nn as $k => $v) {
        $ar = explode("=", $v);
        if (trim($ar[0]) != "") {
            $arr2[trim($ar[0])] = trim($ar[1]);
        }
    }
    $s = "";
    foreach ($arr2 as $k => $v) {
        $s .= $k . "=" . $v . ";";
    }
    return $s;
}

function recontent($re, $nr, $index = 1)
{
    $re = str_replace("\"", "\\\"", $re);
    preg_match("/$re/Uisx", $nr, $nn);
    return $nn[$index];
}

function recontents($re, $nr, $index = 1)
{
    $re = str_replace("\"", "\\\"", $re);
    preg_match_all("/$re/Uisx", $nr, $nn);
    return $nn[$index];
}

function clubb($html, $ob = null)
{
    $GLOBALS['ob'] = $ob;
    $html = preg_replace("/<script[^<>].*>.*<\/script>/Uisx", "", $html);
    $html = preg_replace("/<style[^<>].*>.*<\/style>/Uisx", "", $html);
    $html = preg_replace("/<(?!\/?(?:b\b|br\b|strong\b|p\b|img\b|table\b|tr\b|td\b|th\b))[^<>]*>/Uisx","",$html);
    $html = preg_replace("/<br>/", "\r\n<br>", $html);
    $html = preg_replace("/<p\b[^<>]*>/", "\r\n\r\n<p>", $html);
    $html = preg_replace("/<\s*\/(p|br)>/", "", $html);
    $html = preg_replace("/<b>|<strong>/", "[b]", $html);
    $html = preg_replace("/<\s*\/b>|<\s*\/strong>/", "[/b]", $html);
    $html_s_exp = array(
        "/\<div class=\"quote\"\>\<blockquote\>(.*?)\<\/blockquote\>\<\/div\>/is",
        "/\<a href=\"(.+?)\".*?\<\/a\>/is",
        "/<br.*>/siU",
        "/[ \t]*\<img src=\"static\/image\/smiley\/comcom\/(.+?).gif\".*?\>[ \t]*/is",
        "/\s*\<img src=[\"\'](.+?)[\"'].*?\>\s*/is",
    );
    $html_r_exp = array(
        "[quote]\\1[/quote]",
        "\\1",
        "\n",
        "[em:\\1:]",
        "\n[img]\\1[/img]\n",
    );
    $html_s_str = array('<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '&nbsp; &nbsp; &nbsp; &nbsp; ', '&nbsp; &nbsp;', '&nbsp;&nbsp;', '&lt;', '&gt;', '&amp;');
    $html_r_str = array('[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', "\t", '   ', '  ', '<', '>', '&');
    $html = trim(str_replace($html_s_str, $html_r_str, preg_replace($html_s_exp, $html_r_exp, $html)));
    if (!function_exists('cbfun5')) {
        function cbfun5($matches)
        {
            return "[img]" . quanurl($matches[1], $GLOBALS['ob']->url, $GLOBALS['ob']->baseurl) . "[/img]";
        }
    }
    $html = preg_replace_callback("/<(\/)?(table|tr|td|th)([^<>]*)>/Uisx", function ($em) {
        if (preg_match("/alian\s*=\s*['\"]?(left|right|center)/Uisx", $em[3], $nn)) {
            $align = $nn[1];
        }
        if ($align != "" && $em[1] == "/") {
            $result = "[/align]";
        } else {
            $result = "[" . $em[1] . $em[2];
        }
        if (preg_match("/colspan\s*=\s*['\"]?([0-9]+?)/Uisx", $em[3], $nn)) {
            $colspan = $nn[1];
        }
        if (preg_match("/rowspan\s*=\s*['\"]?([0-9]+?)/Uisx", $em[3], $nn)) {
            $rowspan = $nn[1];
        }
        if (preg_match("/width\s*=\s*['\"]?([0-9]+?%??)/Uisx", $em[3], $nn)) {
            $width = $nn[1];
        }
        if ($colspan != "" || $rowspan != "") {
            $colspan = $colspan == "" ? 1 : $colspan;
            $rowspan = $rowspan == "" ? 1 : $rowspan;
            $result .= "=$colspan,$rowspan";
        }
        if ($width != "") {
            if (preg_match("/[0-9]+%?$/", $result)) {
                $result .= ",$width";
            } else {
                $result .= "=$width";
            }
        }
        $result .= "]";
        if ($align != "" && $em[1] == "") {
            $result .= "[align=$align]";
        }
        return $result;
    }, $html);
    $html = cltable($html);
    $html = preg_replace("/<p\b[^<>]*>/Uisx","",$html);
    $html = preg_replace("/\r\n/Uis",PHP_EOL,$html);
    $html = preg_replace("/<</Uis","《",$html);
    $html = preg_replace("/>>/Uis","》",$html);
    //$html = preg_replace_callback("/\[img\](.*)\[\/img\]/Uisx", "cbfun5", $html); //错误，把urlencode过的url参数解密了
    unset($GLOBALS['ob']);
    return $html;
}

if (!function_exists('cbfun81')) {
    function cbfun81($em)
    {
        return urlencode($em[1]);
    }
}

function httpheadertoarray($s)
{
    $s=preg_replace("/\"(.*)\"(\,|\s|$)/Uisx","\\1".PHP_EOL,$s);
    $arr = preg_split("/\s*(\r|\n)/im", $s);
    $s2="array(";
    for($i=0;$i<count($arr);$i++){
        if($arr[$i]==""||$arr[$i]==null){
            unset($arr[$i]);
        }else {
            $s2 .= "\"{$arr[$i]}\",";
        }
    }
    return $arr;
}

function csurlencode($url)
{
    $url = preg_replace_callback("/([\x{4e00}-\x{9fa5}A-Za-z0-9_]+)/uisx", "cbfun81", $url);
    $url = preg_replace("/[\s| ]/", "%20", $url);
    $url = preg_replace("/—/Uisx", "%e2%80%94", $url);
    if (preg_match("/(alicdn\.com|tmall\.com).*\?/Uisx", $url)) {
        $url=preg_replace("/tbpm=[0-9]+/","",$url)."&tbpm=3";
    }
    return $url;
}

function clPublicres($res, $tempnr)
{
    $return = "";
    if ($res != "") {
        $dd = preg_split("/\|\|\||$/m", $res);
        foreach ($dd as $onedd) {
            if (trim($onedd) == "" || trim($onedd) == "@@") continue;
            $mm = preg_split("/@@/", $onedd);
            $mm[0] = trim($mm[0]);
            pqre($mm[0], $return,$tempnr);
            if ($return != "") return $return;
            preg_match_all("/" . trim($mm[0]) . "/Uisxu", $tempnr, $nn);
//            if(preg_match("/记者/",trim($mm[0]))){
//                printr($nn);
//            }
            if (trim($return) == "" && trim(strip_tags($nn[1][0])) != "") {
                $return = trim(strip_tags($nn[1][0]));
                if (trim($return)!="") break;
            }
        }
    }
    return $return;
}

function changGBK($pagehtml)
{
    if (!function_exists("func")) {
        function func($em)
        {
            $em[1] = urlencode($em[1]);
            return $em[1];
        }
    }

    $pagehtml = preg_replace_callback("/([\x{4e00}-\x{9fa5}\x{f900}-\x{fa2d}\x{3000}-\x{301e}\x{fe10}-\x{fe19}\x{fe30}-\x{fe44}\x{fe50}-\x{fe6b}\x{ff01}-\x{ffee}\x{201C}\x{201D}\s ])/u", "func", $pagehtml);
    $pagehtml = preg_replace("/[ \+]/", "%20", $pagehtml);
    $pagehtml = preg_replace("/—/", "%20", $pagehtml);
    return $pagehtml;
}

function Utf8($pagehtml)
{
    if (preg_match("/<meta[^<>]+charset=(['\"]?)([a-zA-Z0-9\-]+?)\\1/Uisx", $pagehtml, $matches)) {
        $charset = str_replace("-", "", strtolower($matches[2]));
    }
    if ($charset != "utf8") {
        $charset = (!preg_match("/（，|。|？|；）/", $pagehtml)) ? $charset : "utf8";
    }
    $e = mb_detect_encoding($pagehtml, "UTF-8, ISO-8859-1, GBK");
    if ($charset != "utf8" && $e != "UTF-8") {
        $pagehtml = @mb_convert_encoding($pagehtml, "utf-8", "GB2312, GBK,ISO-8859-1");
        $e = mb_detect_encoding($pagehtml, "UTF-8, ISO-8859-1, GBK");
        if ($e == "ISO-8859-1") {
            $pagehtml = iconv("GB2312", "UTF-8//IGNORE", $pagehtml);
        }
    }
    return $pagehtml;
}

function curl2($url, $Querystring = "", $cookie2 = "", $Referer = "", $header = 0)
{
    static $cookie;
    $oldurl="";
    $oldcookie="";
    $proxy=0;
    if ($cookie == null) $cookie = $cookie2;
    $host = whost($url);
    $Referer = "http://{$host}/";
    $timeout = 15;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
    curl_setopt($ch, CURLOPT_HEADER, 1);
    //curl_setopt($ci, CURLOPT_PROXY, '192.168.1.130:8080');//自己设置的代理，
    //curl_setopt($ci, CURLOPT_PROXYUSERPWD, 'username:pwd');//公司上网的账号密码，
    //curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    /*if(preg_match("/multipart/Uisx",$post)){
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=$boundary"));
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    }*/
    if ($Referer != "") curl_setopt($ch, CURLOPT_REFERER, $Referer);
    if ($cookie != "") curl_setopt($ch, CURLOPT_COOKIE, $cookie2);
    if ($Querystring != "") {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $Querystring);
    }
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLINFO_HEADER_OUT, $header);
    $r = curl_exec($ch);
    curl_getinfo($ch, CURLINFO_HEADER_OUT);
    curl_close($ch);
    if (preg_match("/Location:\s*([^\r\n]+)/isx", $r, $nn)) {
        $GLOBALS['jumpurl'] = "";
        if ($url != trim($nn[1]) && $oldurl != $url) {
            $oldurl = $url;
            $url = quanurl(trim($nn[1]), $oldurl);
            $GLOBALS['jumpurl'] = $url;
            $r = curl_file_get_contents($url, $cookie, $Referer, $header, $proxy);

        }
    }

    if (preg_match("/self\.location=[\"']([^<>\"\']*)[\"']/Uisx", $r, $nn)) {
        $GLOBALS['jumpurl'] = "";
        $nn[1] = quanurl($nn[1], $url);
        if ($url != trim($nn[1]) || $oldurl != $url || $cookie != $oldcookie) {
            $oldurl = $url;
            $oldcookie = $cookie;
            $zz = parse_url($url);
            $url = quanurl(trim($nn[1]), "http://" . $zz['host'] . "/");
            $r = curl_file_get_contents($url, $cookie, $Referer, 1);
            $GLOBALS['jumpurl'] = $url;
        }
    }
    $GLOBALS['returncookie'] = $cookie = getcookies($r, $cookie2);
    if (preg_match("/^http\/(.*)(?:\r\n\r\n|\n\n)(.+?)$/Uis", $r, $nn)) {
        $body = $nn[2];
        if (!preg_match("/html|img/Uisx", $r) && @gzinflate(substr($body, 10))) {
            $body = gzinflate(substr($body, 10));
        }
    }
    if ($header) {
        $result = $nn[1] . "\r\n\r\n" . $body;
    } else {
        $result = $body;
    }
    return $result;
}

function ubbtohtml($str)
{
    if(is_array($str)){
        for($i=0;$i<count($str);$i++){
            $str[$i]['message']=ubbtohtml($str[$i]['message']);
        }
    }elseif(is_string($str)) {
        $str=preg_replace("/<(script|object)[^<>]*>.*<\/\\1>/Uisx","",$str);
        $str = preg_replace("/<(?!\/?(?:b\b|br\b|strong\b|p\b|img\b|table\b|tr\b|th\b|td\b|em\b|span\b|script))[^<>]*>/Uisx","",$str);
        $str = preg_replace("/\[url=([^<>\[\]]*)\]([^<>]*)\[\/url\]/", "<a href=\"\\1\">\\2</a>", $str);
        $str = preg_replace("/((<strong>)(\s|　|\&nbsp\;)*)+/i", "\\2", $str);
        $str = preg_replace("/(<\s?br\s*\/?>\s*)+/s", "<br>", $str);
        $str = preg_replace("/^　　/m", "<p>　　", $str);
        $str = preg_replace("/\[hr\]/s", "<hr>", $str);
        $str = preg_replace("/\[b\](.*)\[\/b\]/Uisx", "<b>\\1</b>", $str);
        $str = preg_replace("/\[flash\].*\[\/flash\]|\[\/?b\]/i", "", $str);
        $str = preg_replace("/\[align=(center|left|right)\](.*)\[\/align\]/Uisx", "<p align=\\1>\\2</p>", $str);
        $str = preg_replace("/\[\/align=(center|left|right)\]|\[\/align\]/Uisx", "", $str);
        $str = preg_replace("/\[align=center\]r\[\/align\]/Uisx", "", $str);
        $str = preg_replace("/((<strong>)(\s|　|\&nbsp\;)*)+/i", "\\2", $str);
        $str = preg_replace("/(<(?:p\b|img|^)>(\s|　|\&nbsp\;|<img\s+\/?>|<\/p>)*)+/i", "\n<p>　　", $str);
        $str=preg_replace_callback("/((?:\n|^\s*)<p[^<>]*>)((?:.(?!<\/p>))+(?:\n|\r|\s))(?=<p)/Uisx",function($em){
            $em[0]="\n".$em[1]."　　".preg_replace("/(\n|\r)+$/","",preg_replace("/^(\s|　)+/","",$em[2]))."</p>\n";
            return $em[0];
        }, $str);
        $str = preg_replace("/\[img\]([^<>\[\]]*)\[\/img\]/", "<img src=\"\\1\">", $str);
        $str = preg_replace_callback("/(?:\s|\r)*?<p>　　(<p\s+align|<img|\[img|\[align)/Uisx", function($em){
            if(preg_match("/<p\s+align/i",$em[1])){
                return "\r\n".$em[1];
            }else {
                return $em[1];
            }
        }, $str);
        $str = preg_replace("/\[(\/)?(table|tr|td|th)\]/Uisx", "<\\1\\2>", $str);
        $str = preg_replace("/\[(\/)?(table|tr|td|th)=(\d+%?)\]/Uisx", "<\\1\\2 width=\\3>", $str);
        $str = preg_replace("/\[(\/)?(td|th)=(\d+),(\d+)\]/Uisx", "<\\1\\2 colspan=\\3 rowspan=\\4>", $str);
        $str = preg_replace("/\[(\/)?(td|th)=(\d+),(\d+),(\d+%?)\]/Uisx", "<\\1\\2 colspan=\\3 rowspan=\\4 width=\\5>", $str);
        $str = preg_replace_callback("/\[face=([^\[\]\'\"]*)(?:\"|\'|\:)*\](.*)\[\/face\]/Uisx", function($em){
            if(preg_match("/<span/Uisx",$em[2])){
                $em[2]=preg_replace("/^(.*)style=\"/Uisx","\\1style=\"font-family:{$em[1]};",$em[3]);
            }else {
                return "<span style=\"font-family:{$em[1]}\">{$em[2]}</span>";
            }
            return $em[2];
        }, $str);
        $str = preg_replace_callback("/\[size=([^\[\]\'\"]*)\](.*)\[\/size\]/Uisx", function($em){
            if(preg_match("/<span/Uisx",$em[2])){
                $em[2]=preg_replace("/^(.*)style=\"/Uisx","\\1style=\"font-size:{$em[1]};",$em[2]);
            }else {
                return "<span style=\"font-size:{$em[1]}\">{$em[2]}</span>";
            }
            return $em[2];
        }, $str);
        $str = preg_replace_callback("/\[margin(\-top|\-bottom|\-left|\-right)=(.*)\](.*)\[\/margin\]/Uisx", function($em){
            if(preg_match("/<span/Uisx",$em[3])){
                $em[3]=preg_replace("/^(.*)style=\"/Uisx","\\1style=\"display: block!important;margin{$em[1]}:{$em[2]}!important;",$em[3]);
            }else {
                return "<span style=\"margin{$em[1]}:{$em[2]}\">{$em[2]}</span>";
            }
            return $em[3];
        }, $str);
        $str = preg_replace_callback("/\[color=([^\[\]\'\"]*)(?:\"|\'|\:)*\](.*)\[\/color\]/Uisx", function($em){
            if(preg_match("/<span/Uisx",$em[2])){
                $em[2]=preg_replace("/^(.*)style=\"/Uisx","\\1style=\"color:{$em[1]};",$em[2]);
            }else {
                return "<span style=\"color:{$em[1]}\">{$em[2]}</span>";
            }
            return $em[2];
        }, $str);
        $str = preg_replace("/\[color=([^\[\]]*)\]|\[\/color\]/Uisx", "", $str);
        $str = preg_replace("/\[url=([^\]]*)\]([^\[]+)\[\/url\]/Uisx", "<a href=\"\\1\">\\2</a>", $str);
        $str = preg_replace("/\[url\]([^\[\]]*)\[\/url\]/Uisx", "<a href=\"#\">\\1</a>", $str);
        $str = preg_replace("/\[url=([^\]]*)\]|\[\/url\]/Uisx", "", $str);
        $str = preg_replace("/<p>(\s|　|　|　)*<img/s", "<p><img", $str);
        $str = preg_replace("/\n/", "", $str);
    }
    return $str;
}

function buqi2($s)
{
    return (strlen($s) == 1) ? "0" . $s : $s;
}

//转化标准时间
function bzhsj2($str)
{
    $str=trim(strip_tags($str));
    if (preg_match("/(jan|feb|mar|apr|may|june|july|aug|sept|oct|nov|dec)/i", strip_tags($str))) {
        return date("Y-m-d H:i:s",strtotime(trim($str)));
    }
    if (preg_match("/[0-9]{4}\-[0-9]{2}\-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}/", $str)) {
        return $str;
    }
    if (preg_match("/^(20[0-9]{2})([0-9]{2})([0-9]{2})$/", $str, $nn)) {
        $result = "{$nn[1]}-{$nn[2]}-{$nn[3]} 00:00:00";
    }else if (preg_match("/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})\s*([0-9]{2})?\:?([0-9]{2})?\:?([0-9]{2})?$/", $str, $nn)) {
        $h=($nn[4]=="")?"00":$nn[4];
        $i=($nn[5]=="")?"00":$nn[5];
        $s=($nn[6]=="")?"00":$nn[6];
        $result = "{$nn[3]}-{$nn[2]}-{$nn[1]} {$h}:{$i}:{$s}";
    } elseif (preg_match("/(?:([0-9]{2,4})(?:\-|\.|年|\/|\\\))?(?:([0-9]{1,2})(?:\-|\.|月|\/|\\\))?(?:([0-9]{1,2})(?:\s|日|$))?/", $str, $nn)) {
        $result = ((strlen($nn[1]) == 2) ? "20" . $nn[1] : $nn[1]) . "-" . buqi($nn[2]) . "-" . buqi($nn[3]);
    }
    $result = preg_replace("/\-\-/", "-" . date("m") . "-", $result);
    $result = preg_replace("/\-(\s|$)/", "-" . date("d"), $result);
    $result = preg_replace("/^\-/", date("Y") . "-", $result);

    if (!preg_match("/[0-9]{4}\-[0-9]{2}\-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}/", $result)) {
        if (preg_match("/([0-9]{1,2})(?:\:|时|$|点)(?:([0-9]{1,2})(?:\:|分|$))?(?:([0-9]{1,2}))?/", $str, $nn)) {
            if ($nn[1] <= 23 && ($nn[2] <= 59 || $nn[2] == "") && ($nn[3] <= 59 || $nn[3] == "")) {
                $result .= " " . buqi($nn[1]) . ":" . buqi($nn[2]) . ":" . buqi($nn[3]);
            } else {
                $result .= " 00:00:00";
            }
        }
    }
    $result = preg_replace("/\:\:/", ":00:", $result);
    $result = preg_replace("/\:$/", ":00", $result);
    return $result;
}

function geturl($url)
{
    $resp = file_get_contents($url);
    return $resp;
}

function getjson($url)
{
    $json = geturl($url);
    $json = preg_replace("/^[\x{FEFF}]+/u", "", $json);
    $data = json_decode($json, 1);
    return $data;
}


function pythongeturl($url, $host)
{
    global $t;
    shell_exec("cd " . $_SERVER['DOCUMENT_ROOT'] . "/python&&python geturl.py $url $host");
    $rs = $t->sqlone("select * from cache where url='$url'");
    return $rs;
}

function trimbom($str)
{
    $str = preg_replace("/^\\xEF\\xBB\\xBF/", "", trim($str));
    $str = preg_replace("/^[\x{FEFF}]+/u", "", $str);
    return $str;
}

//http://finance.china.com.cn/hz/sh/photo/ifeng/20180921/2861.shtml?pic=2
//yzs //内容 //列表 解释 jsdata 函数成为数组  ===nodejs
function nodecode22($jsdata)
{
    global $url, $gather_type;
    $str="";
    if(!preg_match("/\:/",$jsdata)||!preg_match("/\{/",$jsdata)) return null;
    if(preg_match("/^\w+\((.*)\)/",$jsdata,$nn)){
        $jsdata=$nn[1];
    }
    if(preg_match("/\{'/Uisx",$jsdata)){
        $jsdata=str_replace("'","\"",$jsdata);
        $jsdata=preg_replace("/True/i","true",$jsdata);
        $jsdata=preg_replace("/False/i","false",$jsdata);
    }
    $jsdata=trim($jsdata);
    if(preg_match("/^\"(.*)\"?\s*$/Uisx",$jsdata,$nn)){
        $jsdata=stripcslashes($nn[1]);
    }
    if(!preg_match("/\'|\"/Uisx",$jsdata,$nn)){
        $jsdata=urldecode($jsdata);
    }

    //一、先用最简单的处理,看是否成功
    $jsdata=@mb_convert_encoding($jsdata, "utf-8", "GB2312,utf-8, GBK,ISO-8859-1");
    $result = json_decode($jsdata, 1);
    if (is_array($result)) {
        return json_decode(json_encode($result), 1);
    } else if (is_array($result)) {
        return $result;
    } else {
        $jsdata = cleanjsonstr($jsdata);
        $result = json_decode($jsdata, 1);
        if (is_array($result)) {
            return $result;
        }else{
            $jsdata = cleanjsonstr2($jsdata);
            $result = json_decode($jsdata, 1);
            if (is_array($result)) {
                return $result;
            }
        }

        $data = json_decode_my($jsdata);
        if (is_array($data)) {
            return $data;
        } else {
            //三、自己用程序一节节分析生成数组,看是否成功
            $nni = 0;
            $NNi = 0;
            $ssi = 0;
            $nnnn = array();
            $NNNN = array();
            $str2 = array();
            $cheng = 1;

            preg_match_all("/((?<!\\\)\"[a-zA-Z0-9_]*(?<!\\\)\")(?<=\"):\s*(?<!\\\)\"([^\{\}\[\]]*)(?<!\\\)\"/Uisx", $str, $nn);
            for ($i = 0; $i < count($nn[1]); $i++) {
                $str = str_replace($nn[0][$i], $nn[1][$i] . ":\"\$strstr{$ssi}\"", $str);
                $nn[2][$i] = @mb_convert_encoding($nn[2][$i], "utf-8", "utf-8,GB2312, GBK,ISO8859-1");
                ${"strstr" . $ssi} = $nn[2][$i];
                $str2[$ssi] = ${"strstr" . $ssi};
                $ssi++;
            }

            do {
                //这里处理有:的对象型
                do {
                    $pattern = "/(?:(\{)|\[)((?:\"[a-zA-Z0-9-_\/\.\?&=\\\#]+\"\s*:\s*(?:\"[^\[\{\}\]]+\"|\\\$nnnn[0-9]+|\[\]|null|true|false|[0-9]+)\,?)+)(?(1)\}|\])/Uisx";
                    try {
                        preg_match_all($pattern, $str, $nn);
                    } catch (Exception $e) {
                        last($url, $gather_type, "yzs1013_pldr.php 表达式出错1：$pattern \r\n\r\nstr:\n$str");
                    }
                    for ($i = 0; $i < count($nn[0]); $i++) {
                        $str = str_replace($nn[0][$i], "\$nnnn{$nni}", $str);
                        $nn[0][$i] = preg_replace("/\\\t/", "tttttt", $nn[0][$i]);
                        $nn[0][$i] = preg_replace_callback("/\\\$(nnnn)([0-9]+)/i", function ($em) use ($NNNN, $nnnn) {
                            return json_encode(${$em[1]}[$em[2]]);
                        }, $nn[0][$i]);
                        $nn[0][$i] = @mb_convert_encoding($nn[0][$i], "utf-8", "utf-8,GB2312, GBK,ISO8859-1");
                        ${"nnnn" . $nni} = json_decode($nn[0][$i], 1);
                        $nnnn[$nni] = ${"nnnn" . $nni};
                        $nni++;
                    }
                } while (preg_match($pattern, $str));

                //这个处理没有:号的数组型
                do {
                    $pattern2 = "/(?:(\{)|\[)((?:\"[^\[\]\{\}]+\"|\\\$nnnn[0-9]+|\[\]|true|false|null)\,?)+(?(1)\}|\])/Uisx";
                    try {
                        preg_match_all($pattern2, $str, $nn2);
                    } catch (Exception $e) {
                        last($url, $gather_type, "yzs1013_pldr.php 表达式出错2：$pattern2 \r\n\r\nstr:\n$str");
                    }
                    for ($i = 0; $i < count($nn2[0]); $i++) {
                        $str = str_replace($nn2[0][$i], "\$NNNN{$NNi}", $str);
                        ${"NNNN" . $NNi} = strToArr($nn2[0][$i], $nnnn, $NNNN);
                        $NNNN[$NNi] = ${"NNNN" . $NNi};
                        $NNi++;
                    }
                } while (preg_match($pattern2, $str));
                $cheng++;
                //echo $str . "\r\n\r\n\r\n";
            } while (preg_match($pattern, $str) || preg_match($pattern2, $str));
            preg_match("/\\\$(nnnn)([0-9]+)/i", $str, $nn);
            $result = eval("return " . $str . ";");
            $json = json_encode($result);
            $json = preg_replace_callback("/.strstr([0-9]+)/isx", function ($em) use ($str2) {
                return preg_replace("/(?<!\\\)\"/Uisx", "\\\"", $str2[$em[1]]);
            }, $json);
            $result = json_decode($json, 1);
            last($url, $gather_type, "yzs1013_pldr.php 进到了nodecode 888", $result);
            if (is_array($result)) {
                return $result;
            }
        }
        //四、最后用提交给nodejs处理,看是否成功
        $data['jsdata'] = $jsdata;
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, 'http://120.77.245.205/python/jsdata.php?XDEBUG_SESSION_START=20181012144922');
        //curl_setopt($curl, CURLOPT_URL, 'http://word.longsunhd.com/python/jsdata.php?XDEBUG_SESSION_START=20181012144922');
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0");
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'Host:' .'120.77.245.205',
            'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0',
            'Connection:  keep-alive',
            'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
            'Accept: application/json, text/javascript, */*; q=0.01',
            'X-Requested-With: XMLHttpRequest',
        ));
        $data = curl_exec($curl);
        curl_close($curl);
        $result=json_decode($data, 1);
        //print_r($result);exit;
        return $result;
    }
}

function jsdata($jsdata)
{

    if (strlen(trim($jsdata)) < 2) {
        return "";
    }
    $result = nodecode($jsdata);
    if (is_array($result)) return $result;

    $data['jsdata'] = $jsdata;
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, 'http://120.77.245.205/python/jsdata.php');
    //curl_setopt($curl, CURLOPT_URL, 'http://word.longsunhd.com/python/jsdata.php?XDEBUG_SESSION_START=20181012144922');
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0");
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
    $data = curl_exec($curl);
    curl_close($curl);
    return json_decode($data, 1);
}

function element($url, $stopstr = ".video", $clickstr = ".player", $stopstr2 = ".video", $timee = 1,$stopiframe="",$clickiframe="",$rand="",$cookieString="")
{
    global $driver,$options,$capabilities;
    $zhurl="http://192.168.196.244:8017/?url=".urlencode($url)."&stopstr=".urlencode($stopstr)."&clickstr=".urlencode($clickstr)."&stopstr2=".urlencode($stopstr2)."&timee=".$timee."&stopiframe=".urlencode($stopiframe)."&clickiframe=".urlencode($clickiframe)."&rand=".$rand."&clickstr=".urlencode($clickstr)."&cookieString=".$cookieString;
    $debugurl="http://element.yangjc.com/?XDEBUG_SESSION_START=54235&url=".urlencode($url)."&stopstr=".urlencode($stopstr)."&clickstr=".urlencode($clickstr)."&stopstr2=".urlencode($stopstr2)."&timee=".$timee."&stopiframe=".urlencode($stopiframe)."&clickiframe=".urlencode($clickiframe)."&rand)=".$rand."&clickstr=".urlencode($clickstr)."&cookieString=".$cookieString;
    $GLOBALS["elementInfo2"]="\n{$zhurl}\n{$debugurl}\n";
    return file_get_contents($zhurl);
    //yzs1013 element
    if (strlen(trim($url)) < 2) {
        return "";
    }
    ini_set('display_errors', 1);
    $return_var = 0;
    if ($return_var === 0) {
    } else {
        echo "Error executing command: " . $return_var . PHP_EOL;
    }
    $options = new ChromeOptions();
    $options->addArguments(['--disable-blink-features=AutomationControlled']);
    $options->addArguments(['--disable-extensions']);
    $options->addArguments(['--disable-gpu']);
    $options->addArguments(['--disable-infobars']);
    $options->addArguments(['--disable-notifications']);
    $options->addArguments(['--disable-popup-blocking']);
    $options->addArguments(['--disable-web-security']);
    $options->addArguments(['--ignore-certificate-errors']);
    $options->addArguments(['--disable-site-isolation-trials']);
    $options->addArguments(['--disable-popup-blocking']);
    $options->addArguments(['--disable-blink-features=AutomationControlled']);
    $options->addArguments(['--disable-features=IsolateOrigins,site-per-process']);
    $options->addArguments(['--allow-file-access-from-files']);
    $options->addArguments(['--no-sandbox']);
    //$options->addArguments(['--headless', '--disable-gpu']);   //这个是无头浏览器
    $options->setExperimentalOption("useAutomationExtension", false);
    $options->setExperimentalOption("excludeSwitches", ['enable-automation']);
    $options->setExperimentalOption('prefs', [
        'profile.default_content_settings.popups' => 0,
        'download.default_directory' => '/d/temp',
    ]);
    $options->addArguments(['--user-data-dir=/d/temp']);
    $capabilities = DesiredCapabilities::chrome();
    $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
    try {
        $driver = RemoteWebDriver::create('http://localhost:9515', $capabilities);
        $driver->get($url);
        $host = host($url);
        $wwwhost = wwwhost($url);
        if ($cookieString == "") {
            $cookieString = getone("select cookie from longzs.longzs_cookies where host='{$wwwhost}'");
            if ($cookieString == "") {
                $cookieString = getone("select cookie from longzs.longzs_re where host='{$host}'");
            }

        }
        $cookies = explode(';', $cookieString);
        foreach ($cookies as $cookiePart) {
            $cookieKeyValue = explode('=', $cookiePart);
            if (count($cookieKeyValue) == 2) {
                $cookieName = trim($cookieKeyValue[0]);
                $cookieValue = trim($cookieKeyValue[1]);
                $driver->manage()->addCookie(array(
                    'name' => $cookieName,
                    'value' => $cookieValue,
                    'domain' => ".{$wwwhost}",  // 设置正确的域名
                    'path' => '/',
                ));
            }
        }

        $driver->get($url);
        $wait = new WebDriverWait($driver, 5);
        if (substr($stopstr, 0, 1) == "." || substr($stopstr, 0, 1) == "#") {
            $sel = "cssSelector";
        } else {
            $sel = "tagName";
        }
        try {
            $stopstr=El::Selector($stopstr);
            $element = $wait->until(
                WebDriverExpectedCondition::visibilityOfElementLocated(
                    WebDriverBy::cssSelector($stopstr)
                )
            );
            $element->click();
            $element = $wait->until(
                WebDriverExpectedCondition::visibilityOfElementLocated(
                    WebDriverBy::$sel($stopstr)
                )
            );
            $html = $driver->getPageSource();
            $driver->quit();
        } catch (Exception $e) {
            $html = $driver->getPageSource();
            $driver->quit();
        }
    }catch(Exception $e){

    }finally {
        if (isset($driver)) {
            $driver->quit();
        }
    }
    return $html;
}


function setlisturlid($url)
{
    global $t;
    if(preg_match("/^https?%3A%2F%2F/Uisx",$url)){
        $url=urldecode($url);
    }
    //$url = preg_replace("/[\?&]zq=[0-9]+/", "", $url);
    //最快插入
    $nn=preg_split("/;|\|/",$url);
    $urlsid=array();
    for($i=0;$i<count($nn);$i++) {
        $url=$nn[$i];
        $data = array('url' => $url);
        //将url入库list_url
        $listid = $t->rk("lists_url", "url", "url='$url'", $data, array("insert" => 1));
        $data = array('url' => $url, 'listurlid' => $listid, 'urltext' => $url, 'urlcode' => substr(md5($url), 0, 15));
        //将url入库 cache
        $t->rk("cache", "url,listurlid,urltext,urlcode", "url='$url'", $data, array("insert" => 1));
        $urlsid[]=$listid;
    }
    return $urlsid;
}

function alistPagesUrlsInsertToCacheByListId($url,$listurlid,$title="",$dateline="")
{
    global $t;
    //将一篇url的listurlid,urltext,urlcode入库,不包括内容
    $id=savePageinfo($url,"",$title,$dateline,$listurlid,array("return"=>"id","gather_type"=>1));
    return $id;
}

function resultsToCache($d,$listid){
    for($i=0;$i<count($d);$i++){
        $url=$d[$i]['url'];
        if($url!=""&&$listid!=""){
            alistPagesUrlsInsertToCacheByListId($url,$listid);
        }
    }
}

function subslongstring($s){
    return preg_replace_callback("/([0-9a-zA-Z \+\.\,\_]{3,})/",function($em){ return substr($em[1],0,3);},$s);
}

//yzs 网址相似度
function is_toodif($nextpage, $url)
{
    $nextpage2 = preg_replace("/\?.*$/", "", subslongstring($nextpage));
    $url2 = preg_replace("/\?.*$/Uisx", "", subslongstring($url));
    $lcs = new LCS();
    if (basename($nextpage) != basename($url) && !preg_match("/-|_/", basename($nextpage)) && preg_match("/(html|htm|shtml|shtm)$/", basename($nextpage))) {
        //return true;
    }
    $xingshidu = $lcs->getSimilar($url2, $nextpage2) * 100;
    return $xingshidu < 80 ? true : false;
}

class LCS
{
    var $str1;
    var $str2;
    var $c = array();

    /*返回串一和串二的最长公共子序列
  */
    function getLCS($str1, $str2, $len1 = 0, $len2 = 0)
    {
        $this->str1 = $str1;
        $this->str2 = $str2;
        if ($len1 == 0) $len1 = strlen($str1);
        if ($len2 == 0) $len2 = strlen($str2);
        $this->initC($len1, $len2);
        return $this->printLCS($this->c, $len1 - 1, $len2 - 1);
    }

    /*返回两个串的相似度
  */
    function getSimilar($str1, $str2)
    {
        $len1 = strlen($str1);
        $len2 = strlen($str2);
        $len = strlen($this->getLCS($str1, $str2, $len1, $len2));
        return $len * 2 / ($len1 + $len2);
    }

    function initC($len1, $len2)
    {
        for ($i = 0; $i < $len1; $i++) $this->c[$i][0] = 0;
        for ($j = 0; $j < $len2; $j++) $this->c[0][$j] = 0;
        for ($i = 1; $i < $len1; $i++) {
            for ($j = 1; $j < $len2; $j++) {
                if ($this->str1[$i] == $this->str2[$j]) {
                    $this->c[$i][$j] = $this->c[$i - 1][$j - 1] + 1;
                } else if ($this->c[$i - 1][$j] >= $this->c[$i][$j - 1]) {
                    $this->c[$i][$j] = $this->c[$i - 1][$j];
                } else {
                    $this->c[$i][$j] = $this->c[$i][$j - 1];
                }
            }
        }
    }

    function printLCS($c, $i, $j)
    {
        if ($i == 0 || $j == 0) {
            if ($this->str1[$i] == $this->str2[$j]) return $this->str2[$j];
            else return "";
        }
        if ($this->str1[$i] == $this->str2[$j]) {
            return $this->printLCS($this->c, $i - 1, $j - 1) . $this->str2[$j];
        } else if ($this->c[$i - 1][$j] >= $this->c[$i][$j - 1]) {
            return $this->printLCS($this->c, $i - 1, $j);
        } else {
            return $this->printLCS($this->c, $i, $j - 1);
        }
    }
}

function stripimgflv($textarea)
{
//    $textarea=preg_replace("/<\/?(?!img)[^<>]*>/", "", $textarea);
//    $textarea=preg_replace("/\[img\].*\[\/img\]/Uisx", "", $textarea);
    $textarea = preg_replace("/\[flv\].*\[\/flv\]/Uisx", "", $textarea);
    $textarea = preg_replace("/\[flash\].*\[\/flash\]/Uisx", "", $textarea);
    return $textarea;
}

function pqre(&$re, &$return = null,$tempnr="")
{
    if($re==""||$re==null) return "";
    if($tempnr!="") {
        phpQuery::$defaultCharset = "utf-8";
        $tempnr = pqhtml($tempnr);
        $pqy = phpQuery::newDocumentHTML(trim($tempnr));
        $tempnr == "" ? pq("",$pqy)->htmlOuter() : $tempnr;
    }
    if (substr(trim($re), 0, 1) == "." || substr(trim($re), 0, 1) == "#" || preg_match("/^(div\b|a\b|span\b|p\b|li\b|em\b|h[0-9]+|td\b|th\b|tr\b|strong\b|\bvideo\b)/Uisx", trim($re))) {
        $nn = preg_split("/--/", preg_replace("/(->|\:add|\:nn[0-9]).*$/", "", $re));
        if (count($nn) > 0) {
            $tempre = preg_replace("/(->|\-\-|\:add|\:nn[0-9]).*$/", "", $re);
        }
        $aSstrs = pq($tempre,$pqy);
        foreach ($aSstrs as $li2) {
            $result = pq($li2)->html();
            $tempOuter = pq($li2)->htmlOuter();
            for ($j = 1; $j < count($nn); $j++) {
                if ($nn[$j] != ""){
                    $pq2=phpQuery::newDocumentHTML(trim($result));
                    $replaces = pq($nn[$j],$pq2);
                    for ($e = 0; $e < count($replaces); $e++) {
                        $result = trim(str_replace(trim(pq($replaces->elements[$e])->htmlOuter()), "", $result));
                    }
                }
            }

            if (preg_match("/->(.*)(\:nn[0-9]+|$)/Uisx", $re, $nnexe)) {
                if (preg_match("/^[a-zA-Z-_]+\(.*\)$/", $nnexe[1])) {
                    $result = pq($li2)->text();
                    $str = "\$result=" . preg_replace("/xxx/i", "\$result", $nnexe[1]) . ";";
                } else {
                    $str = "\$result=pq(\$li2)->" . $nnexe[1].";";
                }
                $fn = fopen("includetemp.php", "w");
                fwrite($fn, "<" . "?php\r\n" . $str . "\r\n?" . ">");
                fclose($fn);
                include("includetemp.php") or die("pq({$re})公式有误");
                if (!is_string($result) && $result != null) {
                    $result = pq($result)->text();
                }
            }
        }
        //$result=pq(trim($re))->text();
/*        if (!preg_match("/\(.*\)/", $re)) {
            $re = "NO(KEN)ENG";
        }*/
    }
    $return = ($result != "") ? $result : $return;
    return $return;
}

function pqrehtml(&$re, &$html)
{
    if (substr(trim($re), 0, 1) == "." || substr(trim($re), 0, 1) == "#" || preg_match("/^(div\b|a\b|span\b|p\b|li\b|em\b|h[0-9]+|td\b|th\b|tr\b|strong\b)/Uisx", trim($re))) {
        phpQuery::$defaultCharset = "utf-8";
        $tempnr = pqhtml($html);
        $py4 = phpQuery::newDocumentHTML(trim($tempnr));
        $html = pq("",$py4)->htmlOuter();
        $elments = pq($re,$py4);
        for ($e = 0; $e < count($elments); $e++) {
            $html = trim(str_replace(trim($elments[$e]->htmlOuter()), "", $html));
        }
        $html=pqhtml($html);
        phpQuery::newDocumentHTML($html);
    }
    return $html;
}

function matchs($str, $re)
{
    preg_match("/$re/Uisx", $str, $nn);
    return $nn[1];
}

class Jsdata
{
    static function tojsdata($str)
    {
        $nni = 0;
        $NNi = 0;
        $nnnn = array();
        $NNNN = array();
        $strtemp = preg_replace_callback("/(?<!\\\)\"(.*)(?<!\\\)\"/Ui", function ($em) {
            $result = json_encode(@mb_convert_encoding($em[1], "utf-8", "GB2312,utf-8, GBK,ISO-8859-1"));
            $result = preg_replace("/\\\t/", "      ", $result);
            return $result;
        }, $str);
        $strtemp = preg_replace("/\"\:\}/", "\":\"\"}", $strtemp);
        $result = json_decode($strtemp, 1);
        if (count($result) > 0) {
            if ((is_object($result) || is_array($result)) && !empty($result)) {
                return $result;
            } elseif (is_string($result) && $result == "") {
                return json_decode($str);
            }
        } else {
            $str = preg_replace_callback("/(?<!\\\)\"(.*)(?<!\\\)\"/Ui", function ($em) {
                $result = json_encode($em[1]);
                $result = str_replace("{", "&d<;", $result);
                $result = str_replace("}", "&d>;", $result);
                $result = str_replace("[", "&z<;", $result);
                $result = str_replace("]", "&z>;", $result);
                $result = preg_replace("/\\\t/", "      ", $result);
                return $result;
            }, $str);
        }

        do {
            preg_match_all("/(?:(\{)|\[)((?:\"[a-zA-Z0-9-_\/\.\?&=]+\":(?:\"[^\(\[\{\}\]]+\"|\[\]|\\\$nnnn[0-9]+|null|true|false|[0-9]+),?)+)(?(1)\}|\])/Uisx", $str, $nn);

            for ($i = 0; $i < count($nn[0]); $i++) {
                $str = str_replace($nn[0][$i], "\$nnnn{$nni}", $str);
                $nn[0][$i] = preg_replace("/\\\t/", "tttttt", $nn[0][$i]);
                $nn[0][$i] = preg_replace_callback("/\\\$(nnnn)([0-9]+)/i", function ($em) use ($NNNN, $nnnn) {
                    return json_encode(${$em[1]}[$em[2]]);
                }, $nn[0][$i]);
                ${"nnnn" . $nni} = json_decode($nn[0][$i]);
                $nnnn[$nni] = ${"nnnn" . $nni};
                $nni++;
            }
            //echo $str . "\r\n\r\n\r\n";
            preg_match_all("/(?:(\{)|\[)((?:\"[^\[\]\{\}]+\"|\\\$nnnn[0-9]+|\[\]|true|false|null)\,?)+(?(1)\}|\])/Uisx", $str, $nn2);
            for ($i = 0; $i < count($nn2[0]); $i++) {
                $str = str_replace($nn2[0][$i], "\$NNNN{$NNi}", $str);
                ${"NNNN" . $NNi} = self::strToArr($nn2[0][$i], $nnnn, $NNNN);
                $NNNN[$NNi] = ${"NNNN" . $NNi};
                $NNi++;
            }
            //echo $str . "\r\n\r\n\r\n";
        } while (preg_match("/(?:(\{)|\[)((?:\"[a-zA-Z0-9-_\/\.\?&=]+\":(?:\"[^\(\[\{\}\]]+\"|\\\$nnnn[0-9]+|\[\]|null|true|false|[0-9]+),?)+)(?(1)\}|\])/Uisx", $str));
        preg_match("/\\\$(nnnn)([0-9]+)/i", $str, $nn);

        return (json_decode(json_encode(${$nn[1]}[$nn[2]]), 1));
    }

    private static function strToArr($str, $nnnn, $NNNN)
    {
        $arr = array();
        if (preg_match("/(?:(\{)|\[)(((?:\"[^\[\]\{\}]+\"|\\\$nnnn[0-9]+|\[\]|true|false|null)\,?)+)(?(1)\}|\])/Uisx", $str, $nn)) {
            preg_match_all("/(\"[^\[\]\{\}]+\"|\\\$nnnn[0-9]+|\[\]|true|false|null)(?:\,|$)/Uisx", $nn[2], $nn);
            for ($i = 0; $i < count($nn[1]); $i++) {
                $arr[] = self::jxnnnn($nn[1][$i], $nnnn, $NNNN);
            }
        }
        return $arr;
    }

    private static function jxnnnn($name, $nnnn, $NNNN)
    {
        preg_match("/(nnnn)([0-9]+)/i", $name, $nn);
        $result = ${$nn[1]}[$nn[2]];
        if (!empty($result)) {
            foreach ($result as $i => $v) {
                if (is_object($result)) {
                    $result->$i = str_replace("&d<;", "{", $result->$i);
                    $result->$i = str_replace("&d>;", "}", $result->$i);
                    $result->$i = str_replace("&z<;", "[", $result->$i);
                    $result->$i = str_replace("&z>;", "]", $result->$i);
                }
            }
        }
        return $result;
    }
}

function stripdouyutable($textarea)
{
    $index = 0;
    $nn=array();
    while (preg_match("/<table[^<>]*>(?:.(?!\btable\b))*<\/table>/Uisx", $textarea)) {
        preg_match_all("/<table[^<>]*>(?:.(?!\btable\b))*<\/table>/Uisx", $textarea, $nn[$index]);
        for ($i = 0; $i < count($nn[$index][0]); $i++) {
            $textarea = str_replace($nn[$index][0][$i], "{\$nn[$index][0][$i]}", $textarea);
        }
        $index++;
    }
    $textarea = preg_replace("/<(\/?td|\/?th|\/?tr|\/?\btable\b)[^<>]*>/Uisx", "", $textarea);
    while (preg_match("/\{\\\$nn\[[0-9]+\]\[[0-9]+\]\[[0-9]+\]\}/Uisx", $textarea)) {
        $textarea = preg_replace_callback("/\{\\\$nn\[([0-9]+)\]\[([0-9]+)\]\[([0-9]+)\]\}/Uisx", function ($em) use ($nn) {
            $result = $nn[$em[1]][$em[2]][$em[3]];
            return $result;
        }, $textarea);
    }

    preg_match_all("/(<table.*<\/table>)/Uisx", $textarea, $nntt);
    for ($t = 0; $t < count($nntt[1]); $t++) {
        $nntt[0][$t]=preg_replace("/<th\b/","<td",$nntt[0][$t]);
        $nntt[0][$t]=preg_replace("/<\/th\b/","</td",$nntt[0][$t]);
        preg_match_all("/<td[^<>]*>((?:[^<>]|<\/?(?:img|p|span)[^<>]*>)+)<\/td>/Uuisx", $nntt[0][$t], $count);
        //preg_match_all("/<td[^<>]*>((?".">(?:[^<>]|<\/?(?:img|p|span)[^<>]*>)+))<\/td>/Uuisx", $nntt[0][$t], $count); //想不塑源，但这是失败的匹配
        $nospanshu = count($count[1]);
        for ($i = 0; $i < count($count[1]); $i++) {
            if (preg_match("/^\s*$/Uisx", $count[1][$i])) {
                $nospanshu--;
            }
        }
        if ($index > 1 || $nospanshu < 2) {
            $textarea = strip_tags($textarea, "<img><p><table><b><strong><tr><td><th><span>");
            //$textarea = preg_replace("/<\/?tr[^<>]*>/i", "\r\n", $textarea);
        }
    }

    return $textarea;
}

function cltable($html)
{
    while (preg_match("/\[table[^\[\]]*\]((?>.(?!\[table))*)\[\/table\]/Uisx", $html)) {
        preg_match_all("/\[table[^\[\]]*\]((?>.(?!\[table))*)\[\/table\]/Uisx", $html, $nn);
        $html = preg_replace_callback("/\[table[^\[\]]*\]((?>.(?!\[table))*)\[\/table\]/Uisx", function ($em) {
            $em[0] = preg_replace("/[\r\n]/", "", $em[0]);
            $em[0] = preg_replace("/\s+/", " ", $em[0]);
            $em[0] = preg_replace("/table/i", "wtable", $em[0]);
            return $em[0];
        }, $html);
    }
    $html = preg_replace("/w+table/", "table", $html);
    return $html;
}

function strToArr($str, $nnnn, $NNNN)
{
    $arr = array();
    if (preg_match("/(?:(\{)|\[)(((?:\"[^\[\]\{\}]+\"|\\\$nnnn[0-9]+|\[\]|true|false|null)\,?)+)(?(1)\}|\])/Uisx", $str, $nn)) {
        preg_match_all("/(\"[^\[\]\{\}]+\"|\\\$nnnn[0-9]+|\[\]|true|false|null)(?:\,|$)/Uisx", $nn[2], $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            $arr[] = jxnnnn($nn[1][$i], $nnnn, $NNNN);
        }
    }
    return $arr;
}

function jxnnnn($name, $nnnn, $NNNN)
{
    preg_match("/(nnnn)([0-9]+)/i", $name, $nn);
    $result = ${$nn[1]}[$nn[2]];
    if (!empty($result)) {
        foreach ($result as $i => $v) {
            if (is_object($result)) {
                $result->$i = str_replace("&d<;", "{", $result->$i);
                $result->$i = str_replace("&d>;", "}", $result->$i);
                $result->$i = str_replace("&z<;", "[", $result->$i);
                $result->$i = str_replace("&z>;", "]", $result->$i);
            }
        }
    }
    return $result;
}

function re($re, $nr)
{
    preg_match($re, $nr, $nn);
    return $nn;
}

function renn($re, $nr)
{
    preg_match_all($re, $nr, $nn);
    return $nn;
}

function err($url, $gather_type, $info)
{
    $f = $_SERVER['DOCUMENT_ROOT'] . "/log/error_" . date("Ymd") . ".txt";
    createdir(dirname($f));
    $str = date("H:i:s") . " gather_type:{$gather_type} " . $url . " " . $info . PHP_EOL;
    file_put_contents($f, $str, FILE_APPEND);
}

function last($url, $gather_type, $info, $arrinfo = array())
{
    $f = $_SERVER['DOCUMENT_ROOT'] . "/log/last_" . date("Ymd") . ".txt";
    createdir(dirname($f));
    $str = date("H:i:s") . " gather_type:{$gather_type} " . $url . " " . $info . "\r\n";
    if (!empty($arrinfo)) {
        $str .= print_r($arrinfo, 1);
    }
    file_put_contents($f, $str);
}

$jsonindex = 0;
$GLOBALS['strostr'] = array();

function json_decode_my($tempnr)
{
    $data = h1c($tempnr);
    $data = json_decode_my_inc($data);
    return $data;
}

function json_decode_my_inc($data)
{
    if(!empty($data)) {
        foreach ($data as $k => $v) {
            if (is_string($v) && preg_match("/strostr([0-9]+)/isx", $v, $nn)) {
                $data[$k] = stripcslashes(unicode_to_utf8($GLOBALS['strostr'][$nn[1]]));
            } elseif (is_string($v)) {
                $data[$k] = $v;
            } elseif (is_array($v)) {
                $data[$k] = json_decode_my_inc($v);
            }
        }
    }
    return $data;
}

function unicode_to_utf8($str)
{
    $str = preg_replace_callback("#\\\u([0-9a-f]+)#i", function ($m) {
        return iconv('UCS-2', 'UTF-8', pack('H4', $m[1]));
    }, $str);
    return $str;
}


function h1c($tempnr)
{
    static $jsonindex = 0;
    $tempnr = preg_replace_callback("/\:\"(.*)(?<!\\\)\"/Uisx", function ($em) use ($jsonindex) {
        static $jsonindex;
        $jsonindex++;
        $GLOBALS['strostr'][$jsonindex] = $em[1];
        return ":\"strostr{$jsonindex}\"";
    }, $tempnr);
    $tempnr = preg_replace_callback("/\,([\}\]])/Ui", function ($em) {
        return $em[1];
    }, $tempnr);
    return json_decode($tempnr, 1);
}

function cleanjsonstr3($jsdata)
{
    //二、用正则将字串修改成标准的,看是否成功
    //把回车去掉，json不需要回车
    if(substr($jsdata,0,3)=='{\\"'){
        $jsdata=preg_replace("/(\\\u[0-9A-Za-z]{4})/","\\\\\\1",$jsdata);
        $jsdata=stripcslashes($jsdata);
    }
    $str = preg_replace("/\s*(\r|\n)\s*/", "", $jsdata);
    $str = preg_replace_callback("/^[\{\[]\\\\\".*$/Uisx", function ($em2) {
        $em2[0]=preg_replace("/(\\\u[0-9A-Za-z]{4})/","\\\\\\1",$em2[0]);
        $em2[0] = stripcslashes($em2[0]);
        return $em2[0];
    }, $str);
    $str = str_replace(":undefined,", ":0,", $str);
    $str = str_replace("&quot;", "MAOHAO", $str);
    $str = preg_replace("/\\\u003C/Uisx", "<", $str);
    $str = preg_replace("/\\\u003e/Uisx", ">", $str);
    $str = preg_replace("/\\\u002F/Uisx", "/", $str);
    //$str = preg_replace("/'/Uisx", "\u2018", $str);
    $str = preg_replace("/\(/Uisx", "\uFF08", $str);
    $str = preg_replace("/\)/Uisx", "\uFF09", $str);
    $str = str_replace('&#x3D;', "=", $str);
    $str=preg_replace_callback("/\\\\\\\"([^\"]+)\\\"/Uisx",function($em){
        if(preg_match("/((?:\\\)+)\\\u/isx",$em[0],$nn22)) {
            for($i=0;$i<strlen($nn22[1]);$i++) {
                $em[1] = stripcslashes($em[1]);
            }
            $em[1] = unicode_to_utf8($em[1]);
        }
        if(preg_match("/((?:\\\)+)\//isx",$em[0],$nn22)) {
            for($i=0;$i<strlen($nn22[1]);$i++) {
                $em[1] = stripcslashes($em[1]);
            }
        }
        return "\\\"{$em[1] }\"";
    },$str);
    $str = str_replace("/‘/Uisx", "", $str);


    //把冒号前面的没有双引号的键值，用引号框住
    $str = preg_replace_callback("/(?<=(?<=\[|\:|\{|^|\s)\{|\,|(?<=\[|\:|\{)\[)\s*([a-zA-Z0-9_]+)\s*\:\s*(?=\\\\\"|\"|\'|\\\$nnnn[0-9]+|\{|\[|\[\]|null|true|false|[0-9]+)/Uisx", function ($em) {
        return "\"{$em[1]}\":";
    }, $str);

    $str = preg_replace_callback("/(?<=\:)\s*'(.*)'\s*(?=\,|\.|\}|\])/Uisx", function ($em) {
        $em[1] = str_replace('\\', "\\\\", $em[1]);
        $em[1] = str_replace('"', "\\\"", $em[1]);
        $em[1] = preg_replace_callback("/^\\\\\"(.*)\\\\\"$/i", function ($em2) {
            $em2[1] = stripcslashes($em2[1]);
            return $em2[1];
        }, $em[1]);
        return "\"" . $em[1] . "\"";
    }, $str);

    //把大括号和中括号内的单引号字符串，替换成双引号字串
    $str = preg_replace_callback("/(?<=\{|,|\[|\:)\s*(?<!\\\)'([^\:\']*)(?<!\\\)'?\s*(?=\,\s*\"|\]|\:|\})/Uisx", function ($em) {
        $em[1] = str_replace('\\', "\\\\", $em[1]);
        $em[1] = str_replace('"', "\\\"", $em[1]);
        return "\"" . $em[1] . "\"";
    }, $str);

    //去掉剩下的单引号前面的线,以免造成冲突
    $str = preg_replace("/\\\'/Ui", "'", $str);

    //去掉字符后面的.函数处理串
    $str = preg_replace("/\"\.(.*)\,\"(?=[a-zA-Z0-9_]+\"\s*\:)/Uisx", "\",\"", $str);

    //去掉变身的引号,以免造成冲突
    $str = preg_replace_callback("/(?<!\\\)\"(.*)(?<!\\\)\"/Ui", function ($em) {
        return "\"{$em[1]}\"";
    }, $str);



    //去掉元素项，逗号尾巴
    $str = preg_replace_callback("/\,\s*([\}\]])/Ui", function ($em) {
        return $em[1];
    }, $str);
    $str = str_replace("MAOHAO", "\\\"", $str);
    //echo unicode2utf8($str);
    return $str;
}

function cleanjsonstr2($jsdata)
{
    $jsdata=preg_replace("/(\,|\:|\[|\{)\s*\\\\\\\\\"/Uisx","\\1\"",$jsdata);
    $jsdata=preg_replace("/\\\\\\\\\"(?=\,|\}|\:|\])/Uisx","\"",$jsdata);
    $jsdata=preg_replace("/(\,|\:|\[|\{)\s*\\\\\"/Uisx","\\1\"",$jsdata);
    $jsdata=preg_replace("/(\,|\:|\[|\{)\s*\\\\\"/Uisx","\\1\"",$jsdata);
    $jsdata=preg_replace("/\\\\\"(?=\,|\:|\}|\])/Uisx","\"",$jsdata);
    $jsdata=preg_replace("/\\\\\"(?=\,|\:|\}|\])/Uisx","\"",$jsdata);
    $jsdata=preg_replace("/\"\{/Uisx","{",$jsdata);
    $jsdata=preg_replace("/\}\"/Uisx","}",$jsdata);
    $jsdata=preg_replace("/\"\[/Uisx","[",$jsdata);
    $jsdata=preg_replace("/\]\"/Uisx","]",$jsdata);
    $jsdata=preg_replace("/(\,|\:|\[|\{)\s*(\\\)+\\\"/Uisx","\\1\"",$jsdata);
    $jsdata=preg_replace("/(\\\)+\\\"(?=\,|\}|\:|\])/Uisx","\"",$jsdata);
    return $jsdata;
}

function bug($name,$value=array()){
    static $index;
    if($name==">redo"||$name=="redo"){
        $str=$value['url'];
        $index++;
        if($value['redonr']!=""){
            file_put_contents($_SERVER['DOCUMENT_ROOT']."/bug_redotemp{$index}.html",$str."\r\n".$value['redonr']);
        }
    }

    if(!empty($value['array'])){
        $index++;
        file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/bug_array.txt", $str . "\r\n" . print_r($value['array'],1));
    }
    if(!empty($value['json'])){
        $index++;
        file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/bug_json.txt", $str . "\r\n" . print_r($value['json'],1));
    }
    if(!empty($value['file'])){
        $index++;
        $str=$value['url'];
        file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/bug_file{$index}.txt", $str . "\r\n" . $value['file']);
    }
}

function endjson($pageinfo)
{
    global $listinfo;
    //$pageinfo_fileter= zqnews::filter($pageinfo);
    if($_REQUEST['gather_type'] == 6){
        if(is_string($pageinfo)){
            $pageinfo=json_decode($pageinfo,1);
        }
        $pageinfo['listinfo'] = $listinfo['urls_info'];
    }

    $pageinfo_fileter=$pageinfo;


    if(!is_string($pageinfo)){
        $pageinfo = json_encode($pageinfo_fileter);
        if ($pageinfo == "") {
            $pageinfo = CJSON::encode($pageinfo_fileter);
        }
    }

    $pageinfo = preg_replace("/\"\:\s*(\,|\}|\])/Uisx", "\":\"\"\\1", $pageinfo);
    //print_r(json_decode($pageinfo,1));
    if ($_GET['callback'] == "") {
        //内容 步骤17 输出json
        //echo '{"ddfsa":"aaa"}';exit;
        echo trim($pageinfo);
    } else {
        echo $_GET['callback'] . "(" . $pageinfo . ")";
    }
    exit(0);
}



function apijson($pageinfo)
{
    global $listinfo;
    //$pageinfo_fileter= zqnews::filter($pageinfo);
    if($_REQUEST['gather_type'] == 6){
        if(is_string($pageinfo)){
            $pageinfo=json_decode($pageinfo,1);
        }
        $pageinfo['listinfo'] = $listinfo['urls_info'];
    }

    $pageinfo_fileter=$pageinfo;

    bug(">END.");
//todo 最后输出

    $data=array(
        "code"=>1,
        "msg"=>"",
        "data"=>$pageinfo_fileter,
        "time"=>time(),
        );

    if(!is_string($pageinfo)){
        $pageinfo = json_encode($data);
        if ($pageinfo == "") {
            $pageinfo = CJSON::encode($data);
        }
    }

    $pageinfo = preg_replace("/\"\:\s*(\,|\}|\])/Uisx", "\":\"\"\\1", $pageinfo);
    //print_r(json_decode($pageinfo,1));
    if ($_GET['callback'] == "") {
        //内容 步骤17 输出json
        //echo '{"ddfsa":"aaa"}';exit;
        echo trim($pageinfo);
    } else {
        echo $_GET['callback'] . "(" . $pageinfo . ")";
    }
    exit(0);
}

function tishi($arr){
    return $arr;
}

function safe($str){
    $str=addslashes($str);
    $str = preg_replace("/^\\xEF\\xBB\\xBF/", "", trim($str));
    $str = preg_replace("/^[\x{FEFF}]+/u", "", $str);
    return $str;
}
function safeEasy($str){
    $str=addslashes($str);
    return $str;
}


function ddd5($nn)
{
    global $rs, $thisurl, $thisbaseurl, $TTBB;
    $GLOBALS['rs'] = $rs;
    $GLOBALS['thisurl'] = $thisurl;
    $GLOBALS['thisbaseurl'] = $thisbaseurl;
    $GLOBALS['TTBB'] = $TTBB;
    $str = $TTBB[$nn[1][0]];
    $str = preg_replace("/<table[^<>]*>/Uisx", "[TABLE=50%,#E5EDF2]", $str);
    $str = preg_replace("/<\/table[^<>]*>/Uisx", "[/table]", $str);
    $str = preg_replace("/<tr[^<>]*>/Uisx", "[tr]", $str);
    $str = preg_replace("/<\/tr[^<>]*>/Uisx", "[/tr]", $str);
    $str = preg_replace("/<td[^<>]*>/Uisx", "[td]", $str);
    $str = preg_replace("/<\/td[^<>]*>/Uisx", "[/td]", $str);
    $str = preg_replace("/<th[^<>]*>/Uisx", "[td]", $str);
    $str = preg_replace("/<\/th[^<>]*>/Uisx", "[/td]", $str);
    $str = preg_replace("/<(?!img)[^<>]*>/Uisx", "", $str);
    if (!function_exists('cbfun34')) {
        function cbfun34($em)
        {
            return createimgubb($em[1], $GLOBALS['title'], $GLOBALS['rs']["loadimg"], $GLOBALS['thisurl'], $GLOBALS['thisbaseurl']);
        }
    }
    $str = preg_replace("/<(?:img)[^<>]*src=\"(.*)\"(?:[^<>]|(?<=width)>)*?" . ">/Uisx", "cbfun34", $str);
    unset($GLOBALS['rs']);
    unset($GLOBALS['thisurl']);
    unset($GLOBALS['thisbaseurl']);
    unset($GLOBALS['TTBB']);
    return $str;
}

function urlcode($url,$title="",$dateline=""){
    if($url!="") {
        return substr(md5($url), 0, 15);
    }else{
       return substr(md5(host($url).$title.$dateline), 0, 15);
    }
}


function url255($url){
    if(!preg_match("/^http/Uisx",$url)){
        $url=urldecode($url);
    }
    return substr(url,0,255);
}

function savePageinfo($url, $pageinfo, $title = "",$dateline="",$listurlid="",$params=array("return"=>"pageinfo"),$news=array())
{
    global $t;
    if(!preg_match("/https?\:\/\//",$url)){
        $url=urldecode($url);
    }
    $host = host($url);
    $rs=getre($host);
    extract($params);
    $pageinfo=filter($pageinfo);
    $pageinfo=($pageinfo==null)?"":$pageinfo;
    $data=array();
    $data['title']=$title;
    $data['dateline']=($dateline==null)?"":$dateline;
    $GLOBALS['listid']=$GLOBALS['listid']??0;
    $data['listurlid']=($listurlid=="")?$GLOBALS['listid']:$listurlid;
    if($gather_type==1&&$rs['bturl']){
        if($rs['bturl']){
            $data['url']="";
            $data['urlcode'] = substr(md5($host.$title.$data['dateline']), 0, 15);
        }
        $data['urlcode'] = substr(md5($url), 0, 15);
        $data['url'] = substr($url,0,255);
        $data['urltext'] = $url;
    }else{
        $data['urlcode'] = substr(md5($url), 0, 15);
        $data['url'] = substr($url,0,255);
        $data['urltext'] = $url;
    }

    if(isset($pageinfo['isapi'])&&$pageinfo['isapi']){
        $pageinfo=$params;
        $data['isapi']=1;
        $data['pageinfo']=$pageinfo;
    }else{
        $data['isapi']=0;
    }

    if (is_array($pageinfo)&&!empty($pageinfo)) {
        $pageinfojson=json_encode($pageinfo,JSON_UNESCAPED_UNICODE);
        $data['pageinfo']=$pageinfojson;
    }

    if($news->jsdata){
        $data['jsdata']=json_encode($news->jsdata);
    }
    if($news->jsurl){
        $data['jsurl']=$news->jsurl;
    }
    $id=$t->rk("cache","url,pageinfo,urltext,urlcode,title,dateline,listurlid,isapi,jsurl,jsdata","urlcode='{$data['urlcode']}'",$data,array("insert"=>1));
    $return=($return=="")?"pageinfo":$return;
    return ${$return};
}

//yzs 过滤结果filter
function filter($pageinfo){
    if(substr($_SERVER['REQUEST_URI'],0,25)=="/collect/reset/reset_send"){
        if(isset($pageinfo['rs'])&&is_string($pageinfo['rs'])){
            $pageinfo=json_decode($pageinfo,1);
        }
        unset($pageinfo['rs']);
        return $pageinfo;
    }
    if(is_string($pageinfo)){
        $pageinfo=json_decode($pageinfo,1);
    }

    $s="bug|thisurl|nn66|nn8888|nopage|secexe|maxPageCount|nextpagerem|nextPage|isBao|s_url|bfid|rs|pages|nn888|nn66|resources|inx|bfid|viewlists|source";
    $nn=explode("|",$s);
    $count=count($nn);
    if(is_array($pageinfo)) {
        for ($i = 0; $i < $count; $i++) {
            unset($pageinfo[$nn[$i]]);
        }
        if(!empty($pageinfo['lists'])) {
            for ($i = 0; $i < count($pageinfo['lists']); $i++) {
                for ($j = 0; $j < $count; $j++) {
                    unset($pageinfo['lists'][$i][$nn[$j]]);
                }
            }
        }
    }
    return $pageinfo;
}

function marpageinfo($pageinfo,$newpageinfo){
    if(empty($pageinfo)){
        return $newpageinfo;
    }
    $pageinfo['message']=array_merge($pageinfo['message'],$newpageinfo['message']);
    $pageinfo['lists']=array_merge($pageinfo['lists'],$newpageinfo['lists']);
    return $pageinfo;
}

function getlisturlid($url){
    $id=getOne("select id from lists_url where url='$url'");
    return $id;
}

function setrsnull($data){
    $arr=array("nrzq","listzq");
    for($i=0;$i<count($arr);$i++) {
        if ($data[$arr[$i]] == null || $data[$arr[$i]] == "") {
            $data[$arr[$i]] = "null";
        }
    }
    return $data;
}

function pqhtml($tempnr){
    $tempnr=preg_replace("/^.*(<html[^<>]*>)/Uisx","<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\\1",$tempnr);
    $tempnr = preg_replace("/lang=\"(zh\-CN|GBK|GB2312)\"/Uisx", "", $tempnr);
    $tempnr = preg_replace("/<meta[^<>]+charset=[^<>]*>/Uisx", "", $tempnr);
    $tempnr = preg_replace_callback("/<head[^<>]*>(.*)<\/head>/Uisx", function ($em) {
        $em[1] = preg_replace("/<meta[^<>]*charset[^<>]*>.*<\/meta>/Uisx", "", $em[1]);
        return "<head>{$em[1]}</head>";
    }, $tempnr);
    $tempnr = preg_replace("/<\/head>/Uisx", "<meta content=\"charset=UTF-8\" />\r\n</head>", $tempnr);
    $tempnr= preg_replace('/[^\x{00}-\x{FFFF}]/u', '', $tempnr);
    return $tempnr;
}

function isGB2312($str) {
    $len = strlen($str);
    for ($i = 0; $i < $len; $i++) {
        $highByte = ord($str[$i]);
        if ($highByte >= 0xB0 && $highByte <= 0xF7 && ($i + 1) < $len) {
            $lowByte = ord($str[$i + 1]);
            if ($lowByte >= 0xA1 && $lowByte <= 0xFE) {
                return true;
            }
        }
    }
    return false;
}



function urldecodeUrl($url){
    if($url=="") return "";
    $url=(!preg_match("/https?\:\/\//Uisx", $url)) ? urldecode($url) : $url;
    return $url;
}

function printr($o,$c=0){
    ini_set("display_errors","on");
    if(substr($_SERVER['REQUEST_URI'],0,25)=="/collect/reset/reset_send") {
       print_r($o);
       if(!$c) exit;
    }
}

function imgcolor($imgPath){
    $average = new Imagick($imgPath);
    $average->quantizeImage( 10, Imagick::COLORSPACE_RGB, 0, false, false );
    $average->uniqueImageColors();
    function GetImagesColor( Imagick $im ){
        $colorarr = array();
        $it = $im->getPixelIterator();
        $it->resetIterator();
        while( $row = $it->getNextIteratorRow() ){
            foreach ( $row as $pixel ){
                $colorarr[] = $pixel->getColor();
            }
        }
        return $colorarr;
    }
    $colorarr = GetImagesColor($average);
    foreach($colorarr as $val){
        $r += $val['r'];
        $g += $val['g'];
        $b += $val['b'];
        echo "<div style='background-color: rgb({$val['r']},{$val['g']},{$val['b']});width:50px;height:50px;float:left;'></div>";
    }
    $r = round($r/10);
    $g = round($g/10);
    $b = round($b/10);
    echo "<br><div style='background-color: rgb({$r},{$g},{$b});width:100px;height:100px;float:left;'></div>";
}

function stripfh($str){
    $str=preg_replace("/\&quot\;|\"|\'|\s|　| |\&nbsp\;|\&amp\;|\&|\\\/Uisx","",$str);
    return $str;
}

if(!function_exists('array_column')){
    function array_column($arr,$n){
        $result=array();
        foreach($arr as $k=>$v){
            $result[]=$v[$n];
        }
        return $result;
    }
}

function preg_match_array($arr,$nr,$fieldstr){
    $result=array();
    $fd=explode(",",$fieldstr);
    for($i=0;$i<count($arr);$i++){
        if(preg_match($arr[$i],$nr,$nn)){
            $GLOBALS[$fd[$i]]=$nn[1]?$nn[1]:($nn[2]?$nn[2]:($nn[3]?$nn[3]:$nn[4]));
        }else{
            return false;
        }
    }
    return true;
}

function phpQuery($pagehtml,$s){
    $pagehtml=pqhtml($pagehtml);
    phpQuery::$defaultCharset = "utf-8";
    $pqy = phpQuery::newDocumentHTML(trim($pagehtml));//yzs 经常出问题
    return pq($s);
}

function urlexists($url) {
    $hdrs = @get_headers($url);
    return is_array($hdrs) ? preg_match('/^HTTP\\/\\d+\\.\\d+\\s+(200|301|403|304)\\s+.*$/',$hdrs[0]) : false;
}

//=============公共替换=====================
function kongge($tem,$options=array()){
    if(is_string($tem)) {
        $tem = trim($tem);
        $tem=preg_replace("/(\&nbsp\;| ){4}/Uis","\r\n　　",$tem);
        $tem=preg_replace("/<(\/?)th([^<>]*)>/Uisx","<\\1td\\2>",$tem);
        $tem=preg_replace("/\[(\/?)th([^<>\[\]]*)\]/Uisx","[\\1td]",$tem);
        $tem=preg_replace("/<(script|object)[^<>]*>.*<\/\\1>/Uisx","",$tem);
        $tem = preg_replace("/<(?!\/?(?:b\b|br\b|strong\b|p\b|img\b|table\b|tr\b|th\b|td\b|em\b|span\b))[^<>]*>/Uisx","",$tem);

        //判断首行是否加不加空格，如果文章中间有空两格则头部也空两格，没有的话头部就不用空两格
        $tem=preg_replace_callback("/(。|？|”)　　/Uisx",function($em){
            $em[0]=$em[1]."\n　　";
            return $em[0];
        },$tem);


        $tem=preg_replace_callback("/\[align[^\[\]]*\].*\[\/align\]/Uisx",function($em){
            $em[0]=preg_replace("/(\r|\n)+/","<p>",$em[0]);
            return $em[0];
        },$tem);
        $tem=preg_replace_callback("/(\[(.*)\])/Uisx",function($em){
            $em[0]=preg_replace("/[\r\n]/m","",$em[0]);
            $em[0]=preg_replace("/\[(\s|　)+/","[",$em[0]);
            return $em[0];
        },$tem);
        $tem=preg_replace_callback("/(【(.*)】)/Uisx",function($em){
            $em[0]=preg_replace("/[\r\n]/m","",$em[0]);
            $em[0]=preg_replace("/【(\s|　)+/","【",$em[0]);
            return $em[0];
        },$tem);
        preg_match_all("/(^|\[(?:align)[^\[\]]*\]|<p[^<>]*>)((?:　|  | | |\&\#12288;|)+?)/Uuim", $tem, $nncc);
        $tem=preg_replace("/([\[<](?:a|url|em|b|align)[^\[\]<>]*[\]>])(　|  | | |\&\#12288;|)+/","\\1　　",$tem);
        $tem=preg_replace("/^(　|  | |\s)*/","",$tem);
        $kong2ge=(preg_match("/(^|[align[^\[\]]*]|<p[^<>]*>)((?:　|  | | |\&\#12288;|){2,}|\s{4,}|\t{1,})/m", $tem)&&count($nncc[0]) >= 1)?true:false;
        if(in_array(8,$options)) $kong2ge=1;
        if(in_array(9,$options)) $kong2ge=0;
        if($_SERVER['HTTP_HOST'] == "collect4.longsunhd.com") $kong2ge=1;
        $tem=preg_replace("/<br>/Uisx","\n",$tem);
        //先统统按默认有两空格处理
        $tem=preg_replace_callback("/(<p[^<>]*>)(.*)(<\/p>)/Uisx",function($em){
            $em[2]=preg_replace("/[\r\n]+/isx","",$em[2]);
            return $em[1].$em[2].$em[3];
        },$tem);

        //处理[aligin]
        $preisimg=0;
        $tem=preg_replace_callback("/^([^\r\n]*)/m", function($em){
            global $preisimg;
            if(preg_match("/^( |　|　|\s| | |\&\#12288;|)*$/m",$em[1])){
                $preisimg=(preg_match("/(<img|\[img)/Uisx",$em[0]))?1:0;
                return "";
            }elseif(preg_match("/^( |　|\s| |\&\#12288;|)*[\[<](?:align|img)/Uisx",$em[1])){
                $preisimg=(preg_match("/(<img|\[img)/Uisx",$em[0]))?1:0;
                $em[1]=preg_replace("/^( |　|\s| | |\&\#12288;|)/m","",$em[1]);
            }
                $em[1]=preg_replace_callback("/(<p[^<>]*>)(.*)(<\/p>|$)/Uisx",function($en)use($preisimg){
                    if(preg_match("/center/",$en[1])){
                        return "\n[align=center]{$en[2]}[/align]";
                    }
                    return "\n[align=left]{$en[2]}[/align]";
                },$em[1]);
//                if($preisimg&&(!preg_match("/(。|；|？|！|）)$/",$em[0])&&strlen(strip_tags($em[0]))<130||strlen(strip_tags($em[0]))<130)||$preisimg&&preg_match("/(照|片|摄|影|者|辑|图|现场|实地|拍|景|探望|视察|考察|慰问|采访)(。|；|？|！)?$/",$em[0])&&strlen(strip_tags($em[0]))<130){
//                    $preisimg=0;
//                    if(!preg_match("/^\s*\[align/",$em[1])){
//                        return "\n[align=center]{$em[1]}[/align]";
//                    }
//                }
                $em[1]=preg_replace("/(<\/p[^<>]*>)/","",$em[1]);
                $em[1]=preg_replace_callback("/^(　|\s| | |\&\#12288;|)*(.*)$/m",function($ex){
                    if(preg_match("/^\s*\[align/Uisx",$ex[2])){
                        return $ex[2];
                    }else{
                        return "[align=left]　　{$ex[2]}[/align]";
                    }
                },$em[1]);
                $preisimg=(preg_match("/(<img|\[img)/Uisx",$em[0]))?1:0;
                $em[1]=preg_replace("/^(\[\/?align[^\[\]]*\]|\s|　| | |\&\#12288;|)+$/im","",$em[1]);
                $em[1]=preg_replace("/\n+(\[align[^<>]*\])/","\n\\1",$em[1]);
                $em[1]=preg_replace("/\[align[^\[\]*]((?:.(?!\[\/align]))*)$/Uisx","\\0[/align]",$em[1]);
                $em[1]=preg_replace("/^((?!.*\[align)(?:.(?!\[align[^\[\]]*\]))*)\[\/align\]/Uisx","\\1",$em[1]);
                return $em[1];

        }, $tem);
        $tem=preg_replace("/<(\/?)b>/Uisx","[\\1B]",$tem);
        $tem=preg_replace("/[\r\n]( |　|　|\r|\n|\t|[\x{3000}]| | |\&\#12288;|)+/us","\n",$tem);
        $tem = preg_replace("/(<(?:p\b|br\b|^)[^<>]*>)(\s|　|\&nbsp\;| )+/i", "\n\\1　　", $tem);
        $tem=preg_replace_callback("/((?:\n|^\s*)<p[^<>]*>)((?:.(?!<\/p>))+(?:\n|\r|\s))(?=<p)/Uisx",function($em){
            $em[0]="\n".$em[1]."　　".preg_replace("/(\n|\r)+$/","",preg_replace("/^(\s|　)+/","",$em[2]))."</p>\n";
            return $em[0];
        }, $tem);
        $tem=preg_replace_callback("/(\[(color|center|align)[^\[\]]*\])(.*)(\[\/\\2\])/Uisx",function($em){
            $em[3]=preg_replace("/(\r|\n)+/","",$em[3]);
            return $em[1].$em[3].$em[4];
        },$tem);
        $tem = preg_replace("/((\r|\n)(\s|　|<\/p>| | |\&\#12288;|)*(\n|\r))+/is", "\n", trim($tem));
        if(!preg_match("/^(　|\s| )*\[(?:align|flash|img)/",$tem)){
            $tem= preg_replace("/^( |　|\t|\r|\n| | |\&\#12288;|)+/", "", trim($tem));
            if(!preg_match("/^[<\[](p|img|align|color|tr|td|th|table)[^<>\[\]]*[\]>]/Uisx",$tem)){
                $tem = "　　".$tem;
            }
        }else{
            $tem = preg_replace("/^( |　|\t|\r|\n| | |\&\#12288;|)+/", "", $tem);
        }
        do {
            $tem = preg_replace_callback("/(\[(align|color|url|em|span)[^\[\]]*\])((?:\s|　| | |\&\#12288;||\&nbsp\;)*)(\[\/\\2\])/Uisx", function ($em) {
                return "";
            }, $tem);
        }while(preg_match("/(\s*\[(align|color|url|em)[^\[\]]*\])((?:\s|　| | |\&\#12288;||\&nbsp\;)*)(\[\/\\2\])/Uisx",$tem));

        //统一在这里段首空两格
        $tem=preg_replace_callback("/\s*(\[(align)[^\[\]]*\])(.*)(\[\/\\2\])/Uisx",function($em){
            if(!preg_match("/^\s*\[img\]/i",$em[3])&&!preg_match("/center/i",$em[1])) {
                return PHP_EOL . $em[1] . "　　" . $em[3] . $em[4];
            }else{
                return PHP_EOL . $em[1] . $em[3] . $em[4];
            }
        },$tem);

        $tem = preg_replace_callback("/^( |　|\t| | |\&\#12288;||\&nbsp\;)+(?!(?:\[|<)(?:align|flash|img|p|span|b))(.*)$/m", function($em){
            $em[2]=trim(preg_replace("/^( |　| | |\&nbsp\;|\&\#12288;)+/","",$em[2]));
            return "<p>　　{$em[2]}</p>";
        }, $tem);
        $tem = preg_replace_callback("/^(?: |　|\t| | |\&\#12288;|)*((?:\[|<)(?:align|p)[^<>]*(?:>|\]))(.*)$/Uimx", function($em){
            $em[2]=trim(preg_replace("/^( |　| | |\&\#12288;|)+/","",$em[2]));
            if(!preg_match("/^\s*\[img\]/i",$em[2])&&!preg_match("/center/i",$em[1])) {
                return "{$em[1]}　　{$em[2]}";
            }else{
                return "{$em[1]}{$em[2]}";
            }
        }, $tem);
        do {
            $tem = preg_replace_callback("/(\<(align|color|p|a\b|span)[^\<\>]*\>)((?:\s|　|　|　|| |\&\#12288;||\&nbsp\;)*)(\<\/\\2\>)/Uisx", function ($em) {
                return "";
            }, $tem);
        }while(preg_match("/(\s*\<(align|color|p|a\b|span)[^\<\>]*\>)((?:\s|　|　|　|| | |\&\#12288;||\&nbsp\;)*)(\<\/\\2\>)/Uisx",$tem));

        //处理[align]里面的元素 [color] 不配对的问题
        $tem=preg_replace_callback("/[\n\r](\[align[^\[\]]*\](?:.(?!\[\/align\]))*)(?:\[align[^\[\]]*\](.*)\[\/align\])??\s*(\[\/align\])/Uisx",function($em){
            $str=$em[1].$em[2].$em[3];
            $str=preg_replace("/[\r\n]+/Uis","",$str);
            return $str;
        },$tem);
        $tem=preg_replace("/^(\[\/?align[^\[\]]*\]|\s)+$/im","",$tem);
        $tem=preg_replace("/(\[\/?align[^\[\]]*\]\s*)+$/im","\\1",$tem);
        $tem=preg_replace_callback("/^(\[align[^\[\]]*\])(.*)(\[\/align\])/Uim",function($em){
            $em[2]=preg_replace("/\[color[^\[\]*]((?:.(?!\[\/color]))*)$/Uisx","\\0[/color]",$em[2]);
            return $em[1].$em[2].$em[3];
        },$tem);
        $tem=preg_replace_callback("/^(\[align[^\[\]]*\])(.*)(\[\/align\])/Uim",function($em){
            $em[2]=preg_replace("/^(?!.*\[color)((?:.(?!\[color[^\[\]]*\]))*)\[\/color\]/Uisx","\\1",$em[2]);
            return $em[1].$em[2].$em[3];
        },$tem);
        $tem=preg_replace_callback("/(\[(color)[^\[\]]*\])(.*)(\[\/\\2\])/Uim",function($em){
            $em[3]=preg_replace("/^(\&nbsp\;|\s| |　)*/isx","",$em[3]);
            return $em[1].$em[3].$em[4];
        },$tem);

        //处理是否该空两隔
        if (!$kong2ge) {
            $tem=preg_replace("/(\[align[^<>]*\])　　/Uisx","\\1",$tem);
        }

        $tem = preg_replace("/<p[^<>]*>(\s|　|　|　|| | |\&\#12288;|)*<\/p>/Uisx","",trim($tem));
        $tem = preg_replace_callback("/(<p[^<>]*>)(.*)(<\/p>)/Uisx",function($em){
            $em[2]=preg_replace("/^([^<>]*)<\/(span|em|strong|a)>/Uisx","\\1",$em[2]);
            return $em[1].$em[2].$em[3];
        },$tem);
        $tem=preg_replace("/<\/p>/Uisx","[/align]",$tem);
        $tem=preg_replace("/<p(?! align=center)[^<>]*>/Uisx","[align=left]",$tem);
        if($_REQUEST['ubb']=="0"){
            $tem=ubbtohtml($tem);
            //解决多数在线编辑器缺陷
//            $tem=preg_replace_callback("/<p\s*align=(left|center|right)>((?:.(?!<p))*)<\/p>/Uisx",function($em){
//                return "[align={$em[1]}]".$em[2]."[/align]";
//            },$tem);
        }else{
            $tem=preg_replace("/<\/?span([^<>]*)>/Uisx","",$tem);
            $tem=preg_replace("/\[\/?(face|size|margin)[^\[\]]*\]/Uisx","",$tem);
        }
        if(!in_array(7,array_values($options))){
            $tem = preg_replace("/\[url=[^<>\[\]]*\]|\[\/url\]/Uisx", "", $tem);
            $tem = preg_replace("/<a\s[^<>]*>|<\/a>/Uisx", "", $tem);
        }
        $tem = preg_replace("/(?:\r|\n|\s)*?\[align[^\[\]<>]*\](\s| |　| |\&\#12288;|)*\[\/align\](?:\r|\n|\s)*?/Uisx", "", $tem);
        $tem = preg_replace("/<p[^<>]*>(\s| |　| |\&\#12288;|)*<\/p>/Uisx", "", $tem);
        $tem = preg_replace("/^\s*　　\[align=left\](.*)\[\/align\]/Uisx", "　　\\1", $tem);
        $tem = preg_replace("/(?:\r|\n|\s)*(?:　| )+\[\/align\]/isx", "[/align]", $tem);
        $tem = preg_replace("/　　\[img\]/isx", "[img]", $tem);
        $tem = preg_replace_callback("/(\r|\n)*(\[align[^<>\[\]]*\](( |　|\s|\&nbsp\;)*(?:\[(span|b|color)[^\[\]<>]*\])?( |　|\s|\&nbsp\;)*\[\/?(span|b|color)\]\s*)*\[\/align\](\r|\n)+)/Uis", function($em){
            return "";
        }, $tem);
        $tem = preg_replace_callback("/(\r|\n)*(\<p[^<>\[\]]*\>(( |　|\s|\&nbsp\;)*(?:\<(span|b|color)[^\[\]<>]*\>)?( |　|\s|\&nbsp\;)*\<\/?(span|b|color)\>\s*)*\<\/p\>(\r|\n)+)/Uis", function($em){
            return "";
        }, $tem);
//        //引起表格变乱，表格要素被删除
//        $tem = preg_replace_callback("/\[table[^<>\[\]]*\]((?:.(?!\[table))*)\[\/table\]/Uis", function($em){
//            $iskong=true;
//            preg_match_all("/\[td[^<>\[\]]*\](.*)\[\/td\]/Uisx",$em[1],$nn);
//            for($i=0;$i<count($nn[1]);$i++){
//                if(preg_replace("/\s|\[(?!img|b|\/)[^<>\[\]]*\]|\[\/(?!img|b)[^<>\[\]]*\]|　/Uisx","",$nn[1][$i])!=""){
//                    $iskong=false;
//                    break;
//                }
//            }
//            if($iskong){
//                return "";
//            }else{
//                $em[1]=preg_replace("/\[(?!img|b|\/)[^<>\[\]]*\]|\[\/(?!img|b)[^<>\[\]]*\]/Uisx","",$em[1]);
//                return $em[1];
//            }
//        }, $tem);
        if ($_SERVER['HTTP_HOST'] != "collect4.longsunhd.com") {
            $tem = preg_replace("/((\r|\n)(\s| |　| |\&\#12288;|)*(\n|\r))+/is", "\n", trim($tem));
        }else{
            //$tem = preg_replace("/\[align=left\](.*)\[\/align\]/Uisx", "\\1", $tem);
            $tem = preg_replace("/((\r|\n)(\s| |　| |\&\#12288;|)*(\n|\r)?)+/is", "\n", trim($tem));
            $tem = preg_replace("/\[align[^\[\]]*\]\s*\[img\]/is", "[align=center][img]", $tem); //把图片一律居中
        }
        $tem = preg_replace_callback("/(\r|\n)*(\[align[^<>\[\]]*\]\s*\[img\].*\[\/img\]\s*\[\/align\](\r|\n)+)/Uis", function($em){
            $em[2]=preg_replace("/(\r|\n)+/is","",$em[2]);
            return $em[2];
        }, $tem);
        $tem = preg_replace("/<p align=left>/Uisx", "", $tem);
        $tem=preg_replace("/(\[align[^\[\]]*\])(?:　|　|\s)*(\[(?:flash|img|\b)\])/Uisx","\\1\\2",$tem);
        $tem=preg_replace("/(\[\/(?:flash|img|b)\])(?:　|　|\s)*(\[\/align[^\[\]]*\])/Uisx","\\1\\2",$tem);
    }elseif(is_array($tem)){
        for($i=0;$i<count($tem);$i++){
            if(array_key_exists("message",$tem[$i])) $tem[$i]['message']=kongge($tem[$i]['message'],$options);
        }
    }

     return $tem;
}

function ubb2html($str){
    $str=preg_replace("/\[align=(center|left|right)\]/i","<p align=\"\\1\">",$str);
    $str=preg_replace("/\[\/align\]/i","</p>",$str);
    $str=preg_replace("/\[img\](.*)\[\/img\]/i","<img src=\"\\1\">",$str);
    $str=preg_replace("/\[b\](.*)\[\/b\]/i","<b>\\1</b>",$str);
    $str=preg_replace("/\[color=([^<>\[\]]*)](.*)\[\/color\]/i","<span color=\"\\1\">\\2</span>",$str);
    $str=preg_replace("/\[strong\](.*)\[\/strong\]/i","<b>\\1</b>",$str);
    $str=preg_replace("/\[url=([^<>\[\]]*)\](.*)\[\/url\]/i","<a target=_blank href=\"\\1\">\\2</a>",$str);
    return $str;
}

function similar_text2($str,$str2){
    $s=(strlen($str)>strlen($str2))?$str:$str2;
    return (strlen($s)-@levenshtein($str,$str2))*100/strlen($s);
}

function changecss($checkstr,$replacestr,$nn,$i){
    if(is_string($checkstr)) {
        if ($nn[1][$i] == "#") {
            if (preg_match("/id=\"{$nn[2][$i]}\"|id={$nn[2][$i]}|id='{$nn[2][$i]}'/i", $checkstr)) {
                $replacestr = replaceAndCss(strip_tags($replacestr, "<img><table><tr><td><th><span><p><br><b>"), $nn[3][$i]);
            }
        } elseif ($nn[1][$i] == ".") {
            if (preg_match("/(class|style)=[\"']?[^<>\'\"]*\b{$nn[2][$i]}\b[^<>\'\"]*/i", $checkstr)) {
                $replacestr = replaceAndCss(strip_tags($replacestr, "<img><table><tr><td><th><span><p><br><b>"), $nn[3][$i]);
            }
        }
    }elseif(is_array($checkstr)){
        for($j=0;$j<count($checkstr);$j++) {
            $replacestr = changecss($checkstr[$j], $replacestr, $nn,$i);
        }
    }
    return $replacestr;
}

//====================最多最大相同相似的部分字串=============================
function guolvsamemaxstr($txt,$str){
    if($GLOBALS['guolvsamemaxstr']==""){
        $GLOBALS['guolvsamemaxstr']=$txt;
    }else{
        $txt=$GLOBALS['guolvsamemaxstr']."\n".$txt;
    }
    preg_match_all("/^(.*)$/Uixm",$txt,$nn1);
    preg_match_all("/^(.*)$/Uixm",$str,$nn2);
    for($i=0; $i<count($nn2[1]);$i++) {
        if(in_array($nn2[1][$i],$nn1[1])){
            $str=str_replace($nn2[1][$i],"",$str);
        }
    }

    preg_match_all("/<p[^<>]*>(.*)<\/p>/Uisx",$txt,$nn1);
    preg_match_all("/<p[^<>]*>(.*)<\/p>/Uisx",$str,$nn2);
    for($i=0; $i<count($nn2[1]);$i++) {
        if(in_array($nn2[1][$i],$nn1[1])){
            $str=str_replace($nn2[1][$i],"",$str);
        }
    }
    return $str;
}


function checkCss($checkstr,$replacestr,$rscss){
    preg_match_all("/^(\.|\#)([a-zA-Z_0-9\-]+)\{(.*)\}/Uimx",$rscss,$nn);
    for($i=0;$i<count($nn[0]);$i++){
        $replacestr=changecss($checkstr,$replacestr,$nn,$i);
    }
    $replacestr=preg_replace("/<strong>|<b>/i","[b]",$replacestr);
    $replacestr=preg_replace("/<\/strong>|<\/b>/i","[/b]",$replacestr);
    if(preg_match("/strong|\:bold/i",$checkstr)&&!preg_match("/\[b/i",$replacestr)){
        $replacestr="[b]".strip_tags($replacestr,"<img><table><tr><td><th><span>")."[/b]";
    }
    if(preg_match("/.*(?<!\-)color\:\s*(\#[a-zA_Z0-9]{3,6})/i",$checkstr,$nn)&&!preg_match("/\[color/i",$replacestr)){
        $nn[1]=(preg_match("/\#ffff?f?f?/Uisx",$nn[1]))?"#000000":$nn[1];
        $replacestr="[color={$nn[1]}]".strip_tags($replacestr,"<img><table><tr><td><th><span>")."[/color]";
    }
    if(preg_match("/.*(?<!\-)color=\s*[\"']?([a-zA_Z0-9\#]{3,6})/i",$checkstr,$nn)&&!preg_match("/\[color/i",$replacestr)){
        $nn[1]=(preg_match("/\#ffff?f?f?/Uisx",$nn[1]))?"#000000":$nn[1];
        $replacestr="[color={$nn[1]}]".strip_tags($replacestr,"<img><table><tr><td><th><span>")."[/color]";
    }
    if(preg_match("/.*(?<!\-)color\:\s*(rgb\([0-9\s\,]+\))/i",$checkstr,$nn)&&!preg_match("/\[color/i",$replacestr)){
        $nn[1]=(preg_match("/rgb\(\s*255\s*\,\s*255\s*\,\s*255\s*\)/Uisx",$nn[1]))?"#000000":$nn[1];
        $replacestr="[color={$nn[1]}]".strip_tags($replacestr,"<img><table><tr><td><th><span>")."[/color]";
    }
    if(preg_match("/.*(?<!\-)text-align\:\s*(left|center|right)/i",$checkstr,$nn)&&!preg_match("/^\[align/i",$replacestr)){
        $replacestr="[align={$nn[1]}]".strip_tags($replacestr,"<img><table><tr><td><th><span>")."[/align]";
    }
    return $replacestr;
}

function replaceAndCss($replacestr,$css){
    if(preg_match("/strong|\:bold/i",$css)&&!preg_match("/\[b/",$replacestr)){
        $replacestr="[b]".$replacestr."[/b]";
    }

    if(preg_match("/(?<!\-)font-family\:\s*([^\[\]\;]+)/i",$css,$nn)&&!preg_match("/\[face/",$replacestr)){
        $replacestr="[face={$nn[1]}]".$replacestr."[/face]";
    }

    if(preg_match("/(?<!\-)font-size\:\s*([^\[\]\;]+)/i",$css,$nn)&&!preg_match("/\[size/",$replacestr)){
        $replacestr="[size={$nn[1]}]".$replacestr."[/size]";
    }

    if(preg_match("/margin(\-(?:top|bottom|left|right))\s*\:\s*([^\[\]\;]+)/i",$css,$nncc)&&!preg_match("/\[margin/",$replacestr)){
        $replacestr="[margin{$nncc[1]}={$nncc[2]}]".$replacestr."[/margin]";
    }

    if(preg_match("/(?<!\-)color\:\s*(\#[a-zA_Z0-9]{3,6})/i",$css,$nn)){
        $replacestr=preg_replace("/\[color[^<>\[\]]*\]|\[\/color\]/Uisx","",$replacestr);
        $replacestr=preg_replace_callback("/>([^<>]*)</Uisx",function($em) use($nn){
            return ">[color={$nn[1]}]".$em[1]."[/color]<";
        },$replacestr);
        $replacestr=preg_replace_callback("/\]([^<>]*)\[/Uisx",function($em) use($nn){
            return "][color={$nn[1]}]".$em[1]."[/color][";
        },$replacestr);
    }
    if(preg_match("/(?<!\-)color\:\s*(rgb\([0-9\s\,]+\))/i",$css,$nn)){
        $replacestr=preg_replace("/\[color[^<>\[\]]*\]|\[\/color\]/Uisx","",$replacestr);
        $replacestr=preg_replace_callback("/>([^<>]*)<(?!\/p)/Uisx",function($em) use($nn){
            return ">[color={$nn[1]}]".$em[1]."[/color]<";
        },$replacestr);
        $replacestr=preg_replace_callback("/\]([^<>]*)\[/Uisx",function($em) use($nn){
            return "][color={$nn[1]}]".$em[1]."[/color][";
        },$replacestr);
    }

    if(preg_match("/text-align\:\s*(center|left|right)/i",$css,$nn)&&!preg_match("/\[align/",$replacestr)){
        $replacestr="[align={$nn[1]}]".$replacestr."[/align]";
    }
    return $replacestr;
}

function unlinkTemp(){
    if($_REQUEST['temp']==1&&substr($_SERVER['REQUEST_URI'],0,25)=="/collect/reset/reset_send") {
        $tempPath = $_SERVER['DOCUMENT_ROOT'] . "/collect/temp/";
        if(file_exists($tempPath . ".html")) @unlink($tempPath . ".html");
        if(file_exists($tempPath . "nn99.html")) @unlink($tempPath . "nn99.html");
        if(file_exists($tempPath . "CollectLib.html")) @unlink($tempPath . "CollectLib.html");
        if(file_exists($tempPath . "pagehtml.html")) @unlink($tempPath . "pagehtml.html");
        if(file_exists($tempPath . "pagehtml0.html")) @unlink($tempPath . "pagehtml0.html");
        if(file_exists($tempPath . "curl_file_get_contents.html")) @unlink($tempPath . "curl_file_get_contents.html");
        if(file_exists($tempPath . "curl38.html")) @unlink($tempPath . "curl38.html");
        if(file_exists($tempPath . "curlbase.html")) @unlink($tempPath . "curlbase.html");
        if(file_exists($tempPath . "element.html")) @unlink($tempPath . "element.html");
        if(file_exists($tempPath . "_re.html")) @unlink($tempPath . "_re.html");
        if(file_exists($tempPath . "err.html")) @unlink($tempPath . "err.html");
    }
}

function getdbhostbyurl($url){
    $host=host($url);
    $r=query("select cookie,httpheadoption from longzs_re where host='{$host}'");
    return $r[0];
}

function getCurlHeader($ch,$data,$url){
    $s=preg_replace_callback("/^(POST|GET)\s*([^\s]+)\s+http/Uixs",function ($em) use($url){
        if(preg_match("/\?/",$url)){
            return "{$em[1]} {$url}&XDEBUG_SESSION_START=54354 HTTP";
        }
        return "{$em[1]} {$url}?XDEBUG_SESSION_START=54354 HTTP";
     },curl_getinfo($ch, CURLINFO_HEADER_OUT)).http_build_query($data)."\n\n";
    return $s;
}

function lianjiewenzhang($old,$new){
    $xc=0;
    similar_text($old,$new,$xc);
    if(preg_match("/\[img\](.*)\[\/img\]/Uisx",$old,$nnt1)&&preg_match("/\[img\](.*)\[\/img\]/Uisx",$new,$nnt2)&&$nnt1!=$nnt2){
        $xc=0;
        $new=guolvsamemaxstr($old,$new);
    }
    if(preg_match("/<img[^<>]*src=\"(.*)\"[^<>]*\>/Uisx",$old,$nnt1)&&preg_match("/<img[^<>]*src=\"(.*)\"[^<>]*\>/Uisx",$new,$nnt2)&&$nnt1!=$nnt2){
        $xc=0;
        $new=guolvsamemaxstr($old,$new);
    }
    if($old!=$new&&$xc<50){
        $old .= "\r\n".$new;
    }
    return $old;
}

function cookiestrtoarray($str){
    $arr=array();
    $nn=explode(";",$str);
    for($i=0;$i<count($nn);$i++){
        $nn22=explode("=",$nn[$i]);
        $arr=array_merge($arr,array($nn22[0]=>trim($nn22[1])));
    }
  return $arr;
}

function createnewurl($url,$s_url="",$nr="",&$re){
    $urlcs=array();
    $surlcs=array();
    if(preg_match("/^http/i",$url)) {
        parse_str(parse_url($url)['query'], $urlcs);
    }else{
        preg_match_all("/(?<=\?|&)([a-z0-9_A-Z]+)=([^&]+)/isx",$url,$nn);
        for($i=0;$i<count($nn[1]);$i++) {
            $urlcs["{$nn[1][$i]}"] = $nn[2][$i];
        }
    }
    parse_str(parse_url($s_url)['query'],$surlcs);

    //1.从原网址参数里找
    foreach($urlcs as $i=>$v){
        foreach($surlcs as $j=>$v2) {
            if ($i==$j||$v==$v2){
                $url=preg_replace("/(?<=\?|&){$i}=([^&\s]+)/","{$i}={{$j}}",$url);
            }
        }
    }

    //2.固定的参数
    foreach($urlcs as $i=>$v){
        if(preg_match("/^1[5-9][0-9]{8}$/",$v,$nn)){
            $url=str_replace($nn[0],"{time10}",$url);
        }
        if(preg_match("/^1[5-9][0-9]{11}$/",$v,$nn)){
            $url=str_replace($nn[0],"{time13}",$url);
        }
        $url=str_replace($s_url,"{url}",$url);
        $url=str_replace(urlencode($s_url),"{url}",$url);
    }

    //3.s_url页面里的参数
    $rearr=array();
    $k_array=array();
    foreach($urlcs as $i=>$v){
        $v=addsla($v);
        if($v=="") continue;
        if(@preg_match("/((?:%3D|'|\"|&|\=\s*|\:\s*)(?:[0-9a-zA-Z\_\-%](?!%26))*)%3D{$v}(?=\"|'|&|\s|\s*\,)/Uisx",$nr,$nn)){
            $url=str_replace("$i=$v","{$i}={{$i}}",$url);
            $s="{$nn[1]}%3D([^&\s<>]*)(?=\"|'|&|\s):to{$i}";
            if(!in_array($s,$rearr)&&!in_array($i,$k_array)){
                $rearr[]=trim($s);
                $k_array[]=$i;
            }
        }
        if(@preg_match("/((?:&amp;|&|=|\s|\"|'|\:)(?:[0-9a-zA-Z\_\-%](?!%26))*\s*=\s*[\"']?){$v}(?=\"|'|&|\s|\,)/Uisx",$nr,$nn)){
            $url=str_replace("$i=$v","{$i}={{$i}}",$url);
            $s="{$nn[1]}([^&\s<>]*)(?=\"|'|&|\s):to{$i}";
            if(!in_array($s,$rearr)&&!in_array($i,$k_array)){
                $rearr[]=trim($s);
                $k_array[]=$i;
            }
        }
        if(@preg_match("/((?:%3D|'|\"|&|\=\s*|\s|^)(?:[0-9a-zA-Z\_\-%])*)\s*\:\s*{$v}(?=\"|'|&|\s|\s*\,)/Uisx",$nr,$nn)){
            $url=str_replace("$i=$v","{$i}={{$i}}",$url);
            $s="{$nn[1]}\s*\:\s*([^&\s<>]*)(?=\"|'|&|\s):to{$i}";
            if(!in_array($s,$rearr)&&!in_array($i,$k_array)){
                $rearr[]=trim($s);
                $k_array[]=$i;
            }
        }
    }
    $re=join("\n",$rearr);
    return $url;
}

function myset($name,$value){
    insertupdate("my", array("name"=>$name,"value"=>$value), "select id from my where name='$name'");
}

function myget($name){
    $r=query("select value from my where host='{$name}'");
    return $r[0]['value'];
}

function inserttomy($name,$value){
    global $cn;
    if($_REQUEST['temp']==1) {
        $value=mysqli_real_escape_string($cn,$value);
        $sql = "insert into my (name,value) values ('" . addslashes($name) . "','" . $value . "')";
        $result=mysqli_query($cn, $sql);
        if(!$result){
            $sql = "insert into my (name,value) values ('" . addslashes($name) . "','" . u($value) . "')";
            $result=mysqli_query($cn, $sql);
        }
        return mysqli_insert_id($cn);
    }
}

function debugger($that,$continue=true){
    if($_REQUEST['temp']==1) {
        if(is_array($that)){
            if($that['cur_url']!="") {
                inserttomy("url", print_r($that['cur_url'], 1));
            }else{
                inserttomy("url", print_r($that['url'], 1));
            }
            inserttomy("title", $that['subject']);
            inserttomy("message",$that['message']);
            inserttomy("flash",$that['flash']);
            inserttomy("bj",$that['bj']);
            inserttomy("plate",$that['plate']);
        }else {
            inserttomy("url", print_r($that->url, 1));
            inserttomy("yuannr", print_r($that->yuannr, 1));
            inserttomy("nr", $that->nr);
            inserttomy("jsdata", $that->jsdata);
            inserttomy("getdata", print_r($that->data, 1));
            inserttomy("title", $that->subject);
            inserttomy("message", $that->message);
        }
        if(!empty($that->my)) {
            foreach ($that->my as $k => $v) {
                inserttomy($that->$k, $that->v);
            }
        }

    }
    if(!$continue) exit;
}

if(!function_exists('bugmessage')){
    function bugmessage($mess){
        $GLOBALS['bugmessage'][]=$mess."\r\n";
    }
}

function guolvpoststr($str,$postdata){
    preg_match_all("/^(.*)\:(.*)$/Uimx",$str,$nn);
    $data['httpheader']=array();
    for($i=0;$i<count($nn[1]);$i++){
        if(!in_array($nn[1][$i],array("Cookie","Host","Referer","Content-Length","Referer","RETURNTRANSFER","X-FORWARDED-FOR","SSL-VERIFYHOST","SSL-VERIFYPEER","SSL-VERIFYHOST","Accept-Language","Accept-Encoding"))) {
            if(!preg_match("/(GET|POST)\s/i",$nn[1][$i])) {
                $data['httpheader'][] = "{$nn[1][$i]}:" . trim($nn[2][$i]) . "";
            }
        }
    }
    $data['httpheader'][] = "Content-Length:" . strlen(trim($postdata)) . "";
    return $data['httpheader'];
}

function jsonpage($data){
    echo json_encode($data);
    exit;
}

function easy($arr){
    if(is_string($arr)){
        return $arr;
    }else if(count($arr)==1){
        if(is_string($arr[0])){
            return $arr[0];
        }else {
            if (isset($arr[0])) {
                $arr = $arr[0];
                if (count($arr) == 1) {
                    $arr = $arr[0];
                }
            } else {
                $arr = current($arr);
            }
        }
    }else{
        $newArr=array();
        $isErr=false;
        foreach ($arr as $k=>$v){
            if(is_int($k)&&count($v)==1){
                foreach ($arr[$k] as $k1=>$v1){
                    $newArr[$k1]=$v1;
                }
            }else{
               $isErr=true;
            }
        }
        if(!$isErr){
            $arr=$newArr;
        }
        foreach ($arr as $k=>$v){
            $arr[$k]=easy($v);
        }
    }
    return $arr;

}

function match($str,$re){
    $re=preg_replace("/^\"(.+)\"$/","\\1",$re);
    if(preg_match($re,$str,$nn)){
        return $nn[1];
    }
    return "";
}


